Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you are fighting the framework. The data going into your views should be created at the Last Possible Minute (LPM).</p> <p>Thinking this way, a <code>SelectList</code> is a type to feed the <code>DropDownList</code> HTML helper. It is NOT a place to store data while you decide how to process it.</p> <p>A better solution would be to retrieve your data into a <code>List&lt;T&gt;</code> and then initialize the <code>SelectList</code>(s) when you need to. An immediate benefit of this practice is that it allows you to reuse your <code>List&lt;T&gt;</code> for more than one <code>DropDownList</code>, such as:</p> <pre><code>Country of birth Country of residence </code></pre> <p>These <code>SelectLists</code> all use the Countries list of type <code>List&lt;Country&gt;</code>.</p> <p>You can use your <code>List&lt;T&gt;</code> at the 'last minute' like in this example:</p> <pre><code>public class TaxCheatsFormViewModel { private List&lt;Country&gt; countries { get; set; } public TaxCheat Cheat { get; private set; } public SelectList CountryOfBirth { get; private set; } public SelectList CountryOfResidence { get; private set; } public SelectList CountryOfDomicile { get; private set; } public TaxCheatsFormViewModel(TaxCheat baddie) { TaxCheat = baddie; countries = TaxCheatRepository.GetList&lt;Country&gt;(); CountryOfBirth = new SelectList(countries, baddie.COB); CountryOfResidence = new SelectList(countries, baddie.COR); CountryOfDomicile = new SelectList(countries, baddie.COD); } } </code></pre> <p>The point being that you should keep your data in a <code>List&lt;T&gt;</code> till you really need to output it; the last possible minute (LPM).</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. 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