I am working with an Edit page that have some drop down list and a model. I want to set the seleted value for the dropdown list from viewbag. But cannot do it. Can you suggest any other way to do it.
In the controller I have done like this
ViewBag.TraineeId = _employeeService.GetEmployeeNamelist(SmartSession.CompanyId);
View
<div id="AttributeDetails">
@foreach (var item in Model.TraineeAssignDetail)
{
@Html.Partial("~/Areas/HRM/Views/TraineeAssign/Partial.cshtml", item)
}
</div>
I am passing the model item through in the partial view using @Html.Partial()
<div class="col-md-2 col-sm-2 col-xs-6">
@Html.DropDownList("TraineeId", new SelectList(ViewBag.TraineeId, "Id", "FullName", Model.TraineeId), "--Select--", new { @class = "form-control col-md-7 col-xs-12 default ddlErrorMsg", @id = "ddlMaterialGroupId" })
@Html.ValidationMessageFor(model => model.TraineeId)
</div>
Please show me some way to do it.enter image description here