[英]All my views are strongly typed, how to pass to site.master?
My views all use strongly typed viewmodels. 我的观点都使用强类型视图模型。
Now in my controllers action, I want to set a warning text that will display in my site.master file. 现在,在我的控制器操作中,我想设置一个警告文本,该文本将显示在我的site.master文件中。
If I set the text in my controllers action, how will it be visible in the site.master? 如果我在控制器操作中设置文本,它将如何在site.master中显示?
I'm confused b/c the strongly typed view for the master will be different. 我很困惑b / c主人的强类型视图会有所不同。
(MVC2) (MVC2)
Update 更新
Also, if I am redirecting to another view, even if I set the viewmodel it will not be used because it is redirect, I know mvc has some sort of a single page session, what is that called again? 另外,如果我重定向到另一个视图,即使我设置了viewmodel它也不会被使用,因为它是重定向的, 我知道mvc有某种单页会话,那又是什么呢?
For all of my Strongly Typed ViewModels, I use a common base class and interface for this. 对于我所有的强类型ViewModel,我使用了一个通用的基类和接口。 By default the master page gets them. 默认情况下,母版页会获取它们。
public class ViewModelBase : IViewModel {
public string InformationForMasterPage{get;set;}
}
public class ViewModelHomePage : ViewModelBase{
public string SomeInformationNotNeededForMasterPage{get;set;}
}
public interface IViewModel{
public string InformationForMasterPage{get;set;}
}
At the Top of the Home Page: 在主页顶部:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ViewModelHomePage>" %
Then for the top of the Master Page: 然后是主页面的顶部:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<IViewModel>" %>
And then deep in the master page: 然后深入主页:
<%: Model.InformationForMasterPage %>
Will work just fine. 会工作得很好。
在控制器中,您可以将对象保存在ViewData
或ViewBag
字典中,并从视图和主控中访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.