Q:

Dropdown selected value with ADO data model and ASP.NET MVC4

Having a hard time getting the selected value to stick on an ASP.NET MVC page.
public partial class AdjustedCost
{
    public SelectList BrandList { get; set; }

    public string Brand { get; set; }
}

The BrandList is getting set in the controller:
    private static SelectList BrandList = new SelectList( new[] { "Brand1","Brand2","Brand3" } );

    public ActionResult EditByTextbox(String textBoxEdit)
    {
        ...
        AjustedCost xadjcost = db.xAdjCost.First(e => e.InvtId == textBoxEdit);

        ...
        xadjcost.BrandList = BrandList;

        return View( "Edit", xadjcost);
    }

And in the Edit view:
     @Html.DropDownListFor(model => model.Brand, Model.BrandList )

Is this correct? The dropdown portion is working but the selected value is just returning the top of the list, not the actual currently set value.

A:

You need to pass in selectedValue into the constructor of SelectList(), instead of using that static variable, which has no context to your current value from the DB.
Therefore I would create a method to give you your select list in context of the value you need selected i.e.
private SelectList BrandList(string selectedValue)
{
    SelectList selectList = null;
    List<SelectListItem> selectListItems = null;

    try
    {
        selectListItems = new List<SelectListItem>();
        selectListItems.Add(new SelectListItem { Text = "Brand1", Value = "Brand1" });
        selectListItems.Add(new SelectListItem { Text = "Brand2", Value = "Brand2" });
        selectListItems.Add(new SelectListItem { Text = "Brand3", Value = "Brand3" });
        selectList = new SelectList(selectListItems, "Value", "Text", selectedValue);
    }
    catch (Exception exception)
    {
        exception.Log(); // or whatever you do with your exceptions
    }

    return selectList;
}

Therefore in your action result, this:
xadjcost.BrandList = BrandList;

Becomes:
xadjcost.BrandList = BrandList(whateverTheBrandValueFromYourDbIs);

