Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC Where to keep the values for SelectLists
    primarykey
    data
    text
    <p>I've currently got all of this mess at the top of my ViewModels which I feel violates the purpose of a DTO. For example, this is in the constructor of one of my view models -</p> <pre><code> Dictionary&lt;int, string&gt; chargeGroups = new Dictionary&lt;int, string&gt;(); chargeGroups.Add(1, "Administration"); chargeGroups.Add(2, "Annual Leave"); chargeGroups.Add(3, "Bereavement"); chargeGroups.Add(4, "Customer Installation, Setup &amp; Training"); chargeGroups.Add(5, "Customer Support"); chargeGroups.Add(6, "Internal Training &amp; Education"); chargeGroups.Add(7, "Sales &amp; Marketing"); chargeGroups.Add(8, "Sick"); chargeGroups.Add(9, "Software Devel / Maint / Test"); chargeGroups.Add(10, "Software Upgrade / Patch"); chargeGroups.Add(11, "Other"); chargeGroups.Add(12, "Other Absence"); chargeGroups.Add(13, "Warranty"); chargeGroups.Add(14, "Public Holiday"); chargeGroups.Add(15, "Other Paid Leave"); ChargeGroups = new SelectList(chargeGroups, "Key", "Value"); </code></pre> <p>My viewmodel:</p> <pre><code> [DisplayName("Charge group")] public short? ChargeGroup { get; set; } public SelectList ChargeGroups; </code></pre> <p>then in my view:</p> <pre><code> &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ChargeGroup) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.DropDownListFor(model =&gt; model.ChargeGroup, Model.ChargeGroups) @Html.ValidationMessageFor(model =&gt; model.ChargeGroup) &lt;/div&gt; </code></pre> <p>Where should I be putting this stuff?</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.
 

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