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)

Ramesh PalanivelRank #372 · 6.8K reputationPosted Mar 16, 2017, 1:29 AM EDT
@Html.DropDownList("Conf_Type", ViewBag.Conf_Type as SelectList, new { Value= @Model.Conf_TypeName, @class = "form-control" })Madhav SharmaRank #1,714 · 885 reputationPosted Mar 16, 2017, 4:42 AM EDT
@Html.DropDownList("Conf_Type", ViewBag.Conf_Type as SelectList, new { Value= @Model.Conf_TypeName, @class = "form-control" })