Deepesh
Deepesh

Reputation: 5604

MVC accessing model of view at layout page

I do not know the right approach to do it but I have one strange requirement in Razor

Scenario

I have a layout page being shared in 40 views, the layout pages also contain some label fields.

I have made a base class in Model which contains properties need to be displayed on Layout page, this class gets inherited in each and every model.

So basically when Model is passed to View it contain some properties to be displayed on layout.

Query Is this is a right approach ? (If no then what is the right approach to do it?)

How to access the properties of model at view in layout page.

Upvotes: 2

Views: 15797

Answers (1)

Deepesh
Deepesh

Reputation: 5604

Partial View can be alternate but why not to make a Base class which contains Layout Properties and all the Model inherits Base Class

Check out this for more Pass data to layout that are common to all pages

Upvotes: 2

Related Questions