Select value of drop-down should show in my Edit dropdown

Posted by Madhav1406 under ASP.NET MVC on 3/16/2017 | Points: 10 | Views : 294 | Status : [Member] | Replies : 0
Controller
public ActionResult Index(int? id)
{
VarsityContext VarsityDB = new VarsityContext();
Varsity.Models.Configuration configuration = new Varsity.Models.Configuration();
try
{
if (id != null)
{
configuration = VarsityDB.Configurations.Single(a => a.Conf_ID == id);
ViewBag.Action = "Edit";
}
else
{
ViewBag.Action = "Create";
}
IEnumerable<SelectListItem> basetypes = new SelectList(cwConfiguration.getConfigurationTypes(), "Id", "Name", configuration.Conf_TypeName);
ViewBag.Conf_Type = basetypes;
ViewBag.Conf_TypeName = basetypes;
}
catch (Exception ex)
{
}
return View(configuration);
}
View
@if (ViewBag.Action == "Edit")
{
@Html.DropDownList("Conf_Type", ViewBag.Conf_Type as SelectList, new { selected = @Model.Conf_TypeName, @class = "form-control" })
}
else
{
@Html.DropDownList("Conf_Type", ViewBag.Conf_Type as SelectList, "Select Type", new { required = "required", validationmessage = "Please select Type", selected = @Model.Conf_Type, @class = "form-control" })
}
@Html.HiddenFor(m => m.Conf_TypeName, ViewBag.Conf_TypeName as SelectListItem)




Responses

(No response found.)

Login to post response