title: OrderBy on Model inside a view using foreach loop
body: <p>I am using the following to dropdown displaying all countries in alphabetical order. It works fine. But my question is: Is the following loop ordering the country names in each iteration or it orders only once and then does a usual iteration?</p>
  
  <pre><code>&lt;select id="dropDownID" name="NameID"&gt;
      &lt;option value="NameID"&gt;Select Country...&lt;/option&gt;
      @foreach (var item in Model.OrderBy(item =&gt; item.CountryName))
      {
          &lt;option value="@item.NameID"&gt;@item.CountryName&lt;/option&gt;
      }
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>Why I am sorting inside View and not in Controller</strong>
  I inherited this project from someone who used LinqToSQL for Model. The country table is in the <a href="http://msdn.microsoft.com/en-us/library/bb384429.aspx" rel="nofollow">O/R Designer</a> that does not provide the choice for ordering the table data unless, I think, I modify the auto-generated code for this table but that would mean anytime the table is updated in SQL server I would need to update it in the O/R Designer by deleting and adding it again and hence update the auto-generated code manually as well. The other choice would be to create a SQL View in the SQL server and order the data there - and use that view in the LinqToSQL model. But I want to avoid creating an extra object for just ordering purposes. I think the better choice would be to avoid LinqToSQL altogether and order the data inside Controller.</p>