In Edit view:
I am passing ViewBag list for the ddl
Controller:
ViewBag.CountryList = new SelectList(db.Country, "CountryCode", "Desc");
in edit view:
How do I assign the viewbag to the ddl and set the value that is coming from the model
@Html.EditorFor(model => model.CountryCode) <- contains the Desc Value, currently just shows in a textbox!
thx!
use @Html.DropDownListFor. If you read the parameters that C# specifies you need, its self explanitory. The fact you have the selectList in the viewbag already means you’ve nearly done it all yourself already.
If that doesnt set the correct value for any reason, you can also use