Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The approach you may take will vary greatly depending on the specific scenario. A few options incude:</p> <ul> <li>Doing as you say and adding the conditional in the view</li> <li>Abstracting the conditional (if it is complex) into your view model so that the lines in the view are still simple (just accessing a preset boolean value on your view model).</li> <li>Doing this conditional at the route or controller level and calling a different overall view (which may share a layout (razor) or master view (webforms mvc))</li> </ul> <p>You don't mention explicitly how you would render the controls in the conditional. I assume you would be doing a RenderPartial. So the lines themselves in the view would be quite 'small'.</p> <pre><code>if(myViewModel.ComplexBoolean) // Boolean set in generation of view model Html.RenderPartial('firstPartial') else Html.RenderPartial('secondPartial') </code></pre> <p><strong>EDIT</strong>: If the item you are setting as 'visible' is simply a single control you may just output the control directly e.g.</p> <pre><code>if(myViewModel.ComplexBoolean) { Html.DropDownListFor(m =&gt; m.Type, Model.Types /* An IEnumerable&lt;SelectListItem&gt;*/, new { @class = "myList" }); } </code></pre> <p>Additionally if you didn't want to set that 'Model.Types' property (to save a db hit for example) then the conditional could be in the location you create your view model (either the controller or some service/view model repo). The view could then just check for the properties existance instead:</p> <pre><code>if(Model.Types != null) { Html.DropDownListFor(m =&gt; m.Type, Model.Types /* An IEnumerable&lt;SelectListItem&gt;*/, new { @class = "myList" }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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