Code
ControllerCode
public ActionResult Index(int? id)Code
{Code
VarsityContext VarsityDB = new VarsityContext();Code
Varsity.Models.Configuration configuration = new Varsity.Models.Configuration();Code
tryCode
{Code
if (id != null)Code
{Code
configuration = VarsityDB.Configurations.Single(a => a.Conf_ID == id);Code
ViewBag.Action = "Edit";Code
}Code
elseCode
{Code
ViewBag.Action = "Create";Code
}Code
IEnumerableSelectListItem> basetypes = new SelectList(cwConfiguration.getConfigurationTypes(), "Id", "Name", configuration.Conf_TypeName);Code
ViewBag.Conf_Type = basetypes;Code
ViewBag.Conf_TypeName = basetypes;Code
}Code
catch (Exception ex)Code
{Code
}Code
return View(configuration);Code
ViewCode
@if (ViewBag.Action == "Edit")Code
{TypeScript
@Html.DropDownList("Conf_Type", ViewBag.Conf_Type as SelectList, new { selected = @Model.Conf_TypeName, @class = "form-control" })Code
}Code
elseCode
{TypeScript
@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" })Code
}Code
@Html.HiddenFor(m => m.Conf_TypeName, ViewBag.Conf_TypeName as SelectListItem)

Nilesh ShahRank #42 · 34.2K reputationPosted Mar 17, 2017, 8:58 AM EDT
Madhav SharmaRank #1,714 · 885 reputationPosted Mar 17, 2017, 10:44 PM EDT
Madhav SharmaRank #1,714 · 885 reputationPosted Mar 20, 2017, 4:31 AM EDT
@Html.DropDownList("Conf_Type", ViewBag.Conf_Type as SelectList, new { selected = @Model.Conf_TypeName, @class = "form-control" })@Html.DropDownList("Conf_Type", null, new { @class = "form-control" })@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" })