title: Get dropdownlist selected option from C# list of objects
body: <p>I have an list of objects that I receive in my Razor View in C#</p>
  
  <pre><code> @model IEnumerable&lt;Project.Models.EvaluationObject&gt;
  </code></pre>
  
  <p>In each object of the IEnumerable I have a property called "MaxValue" that I want to put selected in a input select of html.</p>
  
  <pre><code>  foreach(var item in Model){
          &lt;select&gt;
              &lt;option value=1&gt;One&lt;/option&gt;
              &lt;option value=2&gt;Two&lt;/option&gt;
              &lt;option value=3&gt;Three&lt;/option&gt;
              &lt;option value=4&gt;Four&lt;/option&gt;
          &lt;/select&gt;
  
    }
  </code></pre>
  
  <p>For each item I want to build a select input with the value of the item.MaxValue selected</p>
  
  <p>i.e. In the first loop item.MaxValue = 3, then I should build the next select:</p>
  
  <pre><code>       &lt;select&gt;
              &lt;option value=1&gt;One&lt;/option&gt;
              &lt;option value=2&gt;Two&lt;/option&gt;
              &lt;option value=3 selected="selected"&gt;Three&lt;/option&gt;
              &lt;option value=4&gt;Four&lt;/option&gt;
          &lt;/select&gt;
  </code></pre>
  
  <p>The item.MaxValue is ever between 1 and 4, so If the value is 3 the selected value in the select input is 3.</p>
  
  <p>The First solution I had, is to put an if statement in each option, but I think that's impractrical:</p>
  
  <pre><code> foreach(var item in Model){
      &lt;select&gt;
          &lt;option value=1 @if(item.MaxValue==1){&lt;text&gt;selected="selected"&lt;/text&gt;})&gt;One&lt;/option&gt;
          &lt;option value=2 @if(item.MaxValue==2){&lt;text&gt;selected="selected"&lt;/text&gt;}&gt;Two&lt;/option&gt;
          &lt;option value=3 @if(item.MaxValue==3){&lt;text&gt;selected="selected"&lt;/text&gt;}&gt;Three&lt;/option&gt;
          &lt;option value=4 @if(item.MaxValue==4){&lt;text&gt;selected="selected"&lt;/text&gt;}&gt;Four&lt;/option&gt;
      &lt;/select&gt;
  
   }
  </code></pre>
  
  <p>Hope you can help me, May be I should use some JavaScript.</p>