Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You might consider creating an another object that more closely represents the view you are trying to render.</p> <p>Let's say i have an <code>MyDomain.Order</code> object, so I make a view page that looks something like <code>ViewPage&lt;MyDomain.Order&gt;</code>. Now, let's say that I have a menu that is driven off of a logged in user, as example. It wouldn't make sense to have menu as a property of <code>MyDomain.Order</code>. I would create another object, specifically for the view, call it something like <code>OrderPageModel</code> and have <code>MyDomain.Order</code> and <code>List&lt;MenuItem&gt;</code> as properties of this new object, my view being set up as <code>ViewPage&lt;OrderPageModel&gt;</code>.</p> <p>The other thing to consider might be something like <code>Html.RenderAction()</code>. Same scenario, I have a view, and as you mention in your question, it has a master page, and as in my example, lets say it hosts a menu common to your site. You could create a partial view (<code>UserMenu.ascx</code>) and a controller (<code>SiteController.cs</code>) with an action (<code>UserMenu</code>) that calculates the items for the menu. Inside your master page, you can then call <code>&lt;% Html.RenderAction("UserMenu","SiteController") %&gt;</code>.</p> <p>I would use the first example if it could be something made for a particular view: just make it a part of the model. I would use the second example if it was something more generic to the site, like a menu.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload