Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just to give my 2c worth, our project is using a partial view with several jQuery tabs, and each tab rendering its fields with its own partial view. This worked fine until we added a feature whereby some of the tabs shared some common fields. Our first approach to this was to create another partial view with these common fields, but this got very clunky when using EditorFor and DropDownListFor to render fields and drop downs. In order to get the ids and names unique we had to render the fields with a prefix depending on the parent partial view that was rendering it:</p> <pre><code> &lt;div id="div-@(idPrefix)2" class="toHide-@(idPrefix)" style="display:none"&gt; &lt;fieldset&gt; &lt;label for="@(idPrefix).Frequency"&gt;Frequency&lt;span style="color: #660000;"&gt; *&lt;/span&gt;&lt;/label&gt; &lt;input name="@(idPrefix).Frequency" id="@(idPrefix)_Frequency" style="width: 50%;" type="text" value="@(defaultTimePoint.Frequency)" data-bind="value: viewState.@(viewStatePrefix).RecurringTimepoints.Frequency" data-val="true" data-val-required="The Frequency field is required." data-val-number="The field Frequency must be a number." data-val-range-min="1" data-val-range-max="24" data-val-range="The field Frequency must be between 1 and 24." data-val-ignore="true"/&gt; @Html.ValidationMessage(idPrefix + ".Frequency") ... etc &lt;/fieldset&gt; &lt;/div&gt; </code></pre> <p>This got pretty ugly so we decided to use Editor Templates instead, which worked out much cleaner. We added a new View Model with the common fields, added a matching Editor Template, and rendered the fields using the Editor Template from different parent views. The Editor Template correctly renders the ids and names. </p> <p>So in short, a compelling reason for us to use Editor Templates was the need to render some common fields in multiple tabs. Partial views aren't designed for this but Editor Templates handle the scenario perfectly. </p>
    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. 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