When I am applying server side validation, I am getting error in dropdown
The ViewData item that has the key 'Conf_Type' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'. Model : public int Conf_Type { get; set; }
View: @if (ViewBag.Action == "Edit")
{
@Html.DropDownList("Conf_Type", ViewBag.Assets_Type as SelectList, new { @class = "form-control" })
}
else
{
@Html.DropDownList("Conf_Type", ViewBag.Assets_Type as SelectList, "Select Type", new { required = "required", validationmessage = "Please select Type", selected = @Model.Assets_Type, @class = "form-control" })
}
Controller: public ActionResult Index(int? id)
{
VarsityContext VarsityDB = new VarsityContext();
Varsity.Models.Configuration configuration = new Varsity.Models.Configuration();
try
{
TempData["Asset Inventory"] = "Asset Inventory";
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_Type);
ViewBag.Conf_Type = basetypes;
}
catch (Exception ex)
{ }
return View(configuration);
}