Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you have all these properties on your ViewModel which aren't used (i.e null or whatever) it isn't really going to impact performance. What it will impact however, is your design.</p> <p>Generally speaking, one model to rule them all as you are proposing is a bit evil and goes against separation of concerns. ViewModel's <strong>should</strong> be very simple and <strong>should</strong> be tailored to the view. ViewModel's shouldn't really provide the view with more or less data than what the view needs in order to render.</p> <p>Consider this....</p> <p>You have a generic model with 15 properties on it and you only set a handful of them. Somebody else designs a new view and looks at the model, they may not know which of those properties are sent and under what conditions they are set. Consequently they may be attempting to display data that does not exist. This isn't a very clean approach.</p> <p>I would stick to individual view models and where there is common functionality between views, create an abstraction or base ViewModel from which other view models can extend.</p> <p><strong>Edit:</strong> One other thing you could do is use the new MVC 3 (still in preview) syntax (dynamic) for setting ViewData properties directly as if they were properties.</p> <p>So rather than doing</p> <pre><code>ViewData["FirstName"] = "Bob"; </code></pre> <p>You can do </p> <pre><code>ViewModel.FirstName = "Bob"; </code></pre> <p>This gives you dynamic variables automatically in MVC 3.</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