How to pass a model to the MVC 3 Razor "masterpage"
How to pass a model to the MVC 3 Razor "masterpage"?
Razor view engine is different from the aspx vie开发者_运维问答w engine.
The layout page will "inherit" the model of the content page. Are you trying to have the layout page have a different model than the content page?
I'm not sure whether the _Layout.cshtml can have a separate model.
Perhaps would you should look into is a M-V-VM configuration with ViewModels that inherit from a BaseViewModel class that provides the necessary shared data required for the _Layout.cshtml "MasterPage".
Great info on MVVM here: Stack Overflow: MVVM ViewModel vs MVC ViewModel. Also info on pushing shared ViewModel functionality into a base class here: Stack Overflow: Push Common ViewModel functionality into a base class?
[Update] The link in Martin's initial comment, whilst not representing a direct duplicate of your issue, does include some info on how to inject the base ViewModel functionality without the Controller's needing to know anything about it... re-link here: Stack Overflow: Passing Data to Master Page in ASP.Net MVC
There is no difference between view engine because Model is not a part of presentation layer. Use base application controller to create and fill shared model and pass reference to it into ViewBag property of request context. Read:
Passing Data to View Master Pages - an ASP.NET tutorial
ViewBag dynamic in ASP.NET MVC 3
public ActionResult Test(TestModel model)
{
}
TestModel is a model class.. Like this you can pass model to master page
精彩评论