2

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.

2
  • Can't we do it in Partial View? Commented Dec 26, 2012 at 12:09
  • You can't pass Model on Layout page Commented Dec 26, 2012 at 12:12

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I don't like the idea of typing a layout. Why should one always care about populating base properties even if a simple page, probably with some simple or even static data is required. I'd prefer RenderAction in this case. However there is never an ideal solution for every scenario, so maybe it is a typed layout approach you should choose.
What if data gets changes on the basis of views and secondly I know this is not best approach but could be one way to get the things done

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.