Passing model to layout in MS MVC

In the views, I go through a strongly typed model of the method as follows:

System.Web.Mvc.ViewPage<HomeModel> 

And then just use it:

 <%= Model.Greeting %> 

How could a heavily typed model be used in a layout?

Without strict input, I will probably add the necessary data to the factory controller, and then use it via (LayoutModel) Viewdata ["LayoutModel"]). Tralala, but I'm looking for a better way.

0
source share
1 answer

Create a strongly typed property in your view:

 <script runat="server"> protected LayoutModel LayoutModel { get { return ViewData["LayoutModel"] as LayoutModel; } } </script> 
+1
source

All Articles