MVC 4 Create View - Ordering Drop Down for Forgein Key table

I have an MVC4 project using EF6 to which I have added a Controller, Model and related Views using the VS 2012 wizard.

The Create View includes this code (.aspx engine)

    <div class="editor-label">
        <%: Html.LabelFor(model => model.senProviderId, "Site Id") %>
    <div class="editor-field">
        <%: Html.DropDownList("senProviderId", String.Empty) %>
        <%: Html.ValidationMessageFor(model => model.senProviderId) %>

where model.senProviderId references a related (foreign key) table and produces this HTML (segment)

        <div class="editor-field">
        <select id="senProviderId" name="senProviderId"><option value=""></option>
        <option value="3">SW127     </option>
        <option value="4">NE011     </option>
        <option value="5">NE133     </option>
        <option value="6">Out016    </option>
        <option value="104">SE133     </option>

For obvious reasons I need to order the Drop-Down by the Display Value rather then by the underlying key.

How can that best be done?

EDIT: As requested Controller code for the parent table Controller

  public ActionResult Create()
        ViewBag.senHousingCode = new SelectList(db.sssHousingCodes, "hcId", "hcName");
        ViewBag.senProviderId = new SelectList(db.sssProviderProfiles, "prvId", "prvSiteId");
        return View();


OF course - I was looking for decoration on the Model but of course the answer is using OrderBy in the controller code:

 ViewBag.senProviderId = new SelectList(db.sssProviderProfiles.OrderBy(m => m.prvSiteId), "prvId", "prvSiteId");

thanks for the prompt Mikhail!

Need Your Help

NuGet package restore with Mono on Travis CI failing

c# .net mono nuget travis-ci

My project compiles &amp; runs fine on OSX and Windows. However, trying to get it hooked up to Travis CI, I get this error from NuGet (using version 2.8):

ASP.NET MVC markup in VS2008 script has warnings with “expected expression”

javascript jquery visual-studio-2008 ide

I've searched SO and have been unable to find this question asked before, but I can't believe I'm the only one running into it. If this is a duplicate, please point me to the original question.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.