-1

I feel like this is very simple and I have done my research here:

Research

But it is not working.

Controller:

ViewBag.OwnerValue = new SelectList(db.tableName, "ID", "AName", object.OwnerID);

View:

@Html.DropDownListFor(model => model.AID, ViewBag.OwnerValue as SelectList, new { @class = "form-control" })

In my research the answer said to change the name of the ViewBag property so that it doesn't match the actual property name.. so that's what I did and the selected value is still not being set.

Any help is appreciated.

Community
  • 1
  • 1
Grizzly
  • 5,873
  • 8
  • 56
  • 109

1 Answers1

1

You would need to set the model property AID before passing the result to View in your controller action:

ViewBag.OwnerValue = new SelectList(db.tableName, "ID", "AName");

model.AID =  object.OwnerID;
return View(model);
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160