动态变化的主模板在ASP.NET MVC [英] Dynamically changing Master Template in ASP.NET MVC

查看:128
本文介绍了动态变化的主模板在ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要支持我的应用程序(ASP.NET MVC)不同的母版页的要求。
什么是推荐的方式:


  1. 传递母版页名称从视图。

  2. 存储主网页(会话,或东西),这样用户的访问期间,它坚持。


解决方案

使用自定义的基本控制器和它,而不是继承:

 公共类CustomBaseController
    继承System.Web.Mvc.Controller    受保护的覆盖功能视图(BYVAL的viewName作为字符串,BYVAL masterName作为字符串,BYVAL模型作为对象)作为System.Web.Mvc.ViewResult       返回MyBase.View(的viewName,会议(母版),型号)    结束功能末级

我设置在Global.asax在session_start我的Session变量:

 子在session_start(BYVAL发件人为对象,BYVAL E上的EventArgs)//编程弄清楚您的会话
会议(母版)=MyMasterPage结束小组

I have the requirement to support different Master pages on my application (ASP.NET MVC). What is the recommended way to:

  1. Pass the master page name to the view from.
  2. Store the master page (in session, or something) so it sticks during a user's visit.

解决方案

Use a custom base controller and inherit from it instead:

Public Class CustomBaseController
    Inherits System.Web.Mvc.Controller

    Protected Overrides Function View(ByVal viewName As String, ByVal masterName As String, ByVal model As Object) As System.Web.Mvc.ViewResult

       Return MyBase.View(viewName, Session("MasterPage"), model)

    End Function

End Class

I set my Session variable in the global.asax Session_Start:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

//programming to figure out your session
Session("MasterPage")="MyMasterPage"

End Sub

这篇关于动态变化的主模板在ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆