Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@TreyE correctly points out that you never specify that any particular select list item should be selected when displayed in the view.</p> <p>There are several ways you can do this. First is to use the SelectList object and use its constructor that allows you to pass in the object that should be selected, it's the overload <code>SelectList(IEnumerable, String, String, Object)</code> <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist%28v=vs.100%29.aspx" rel="nofollow">MSDN SelectList</a>. </p> <p><code>SelectList</code> is only supported on .NET 3.5+ though FYI.</p> <p>Second, in <code>GetServerTypes()</code> you could write:</p> <pre><code>private List&lt;SelectListItem&gt; GetServerTypes() { List&lt;SelectListItem&gt; sl = new List&lt;SelectListItem&gt;(); IQueryable&lt;ServerType&gt; items = (from t in _entities.ServerTypes select t); foreach (var item in items) sl.add(new SelectListItem { Value = item.id, Text = item.Description, Selected = item.isSelected } ); return sl; } </code></pre> <p>Also remember that only one item should be selected, so make sure that if you do try to use some boolean property it is not possible that more than one <code>item</code> could have its <code>isSelected</code> property set to <code>true</code>. </p> <p>Alternatively, if you need to use some type of <code>if</code> statement to decide if <code>Selected = true</code> (i.e. your item has no isSelected boolean) then you can add that in the <code>foreach</code> loop.</p> <pre><code>foreach(var item in items) { if //condition sl.Add(new SelectListItem { Value = item.id, Text = item.Description, Selected = true }); else sl.Add(new SelectListItem { Value = item.id, Text = item.Description, Selected = false }); } </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. This table or related slice is empty.
    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