I have used a ViewBag
to pass a list of values from controller to be set in a dropdownlist in a Razor view.
In Create
Controller:
List<SelectListItem> status_list = new List<SelectListItem>();
status_list.Add(new SelectListItem() { Text = "Closed", Value = "Closed" });
status_list.Add(new SelectListItem() { Text = "Open", Value = "Open" });
ViewBag.closed_status = new SelectList(status_list, "Value", "Text");
View:
<div class="form-group input-group">
<span class="input-group-addon" style="width: 200px">Closed Status</span>
@Html.DropDownList("closed_status", (SelectList)ViewBag.closed_status, "Select", new { @class = "form-control", @style = "width: 200px", required = "required" })
</div>
I have used the same coding in Edit View/controller also.
I want display the value selected during creating in the edit mode also. But it shows the default value which is "select".
Can you please suggest me a way of displaying the value?