Im populating a dropdownlist from a table, and the problem is when I go to the Edit page, it didnt select the value but instead show "Select Company".
Im using AspNetUsers default table, and add another column on it called Company (Integer).
I have another model & Table called TBL_COMP which map to AspNetUsers.
public class TBL_COMP
{
[Key]
public int CompId { get; set; }
public string CompDesc { get; set; }
}
In my models (UserViewModels) I have this
public int Company { get; set; }
[ForeignKey("Company")]
public TBL_COMP TBL_COMP { get; set; }
This is the dropdownlist in view:
@Html.DropDownListFor(m => m.Company, new SelectList(ViewBag.Company, "Value", "Text"), "Select Company", new { @class = "form-control" })
and this is the controller:
ViewBag.Company = new SelectList(db.TBL_COMP.ToList(), "CompId", "CompDesc", user.Company);