title: using extension method for dropdown
body: <p>I'm currently working on a MVC app which has a create and edit view. Both views are very similar in terms of the UI. On each page I've got around 5-7 dropdowns which I populate in the controller with the help of the following extension method. </p>
  
  <pre><code>public static IEnumerable&lt;SelectListItem&gt; ToSelectListItems&lt;T&gt;(this IEnumerable&lt;T&gt; items, Func&lt;T, string&gt; textSelector, Func&lt;T, string&gt; valueSelector)
  {
     return items.OrderBy(item =&gt; textSelector(item))
           .Select(item =&gt;
           new SelectListItem
           {
             Text = textSelector(item),
             Value = valueSelector(item)
           });
  }
  </code></pre>
  
  <p>Now on edit view I want to display the same dropdowns but this time with the selected value to be set to true to whatever the user selected on the create view. This is how I'm currently doing this</p>
  
  <pre><code>List&lt;SelectListItem&gt; userDdl = new List&lt;SelectListItem&gt;();
  
  foreach (var items in GetUserDropDown(userId, userName))
  {
     userDdl.Add(new SelectListItem { Value = items.Value, Text = items.Text });
  }
  
  userDdl.Where(a =&gt; a.Value == someValueFromDb).First().Selected = true;
  </code></pre>
  
  <p>This works ine but I was thinking is there a better way approach for this or am I stuck with this</p>