Arnis Lapsa
Arnis Lapsa

Reputation: 47567

Passing model to layout in MS MVC

In views i`m passing model strongly typed way like this:

System.Web.Mvc.ViewPage<HomeModel>

And then just use it:

<%= Model.Greeting %>

How it would be possible to use strongly typed model in layout?

Without strongly typing i would probably add necessary data at controller factory, then use it through (LayoutModel)Viewdata["LayoutModel"]).Tralala, but i`m looking for better way.

Upvotes: 0

Views: 940

Answers (1)

eu-ge-ne
eu-ge-ne

Reputation: 28153

Create strongly typed property in your View:

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

Upvotes: 1

Related Questions