When I apply 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'.
Model :
public int Conf_Type { get; set; }
View:
Code
@if (ViewBag.Action == "Edit")Code
{TypeScript
@Html.DropDownList("Conf_Type", ViewBag.Assets_Type as SelectList, new { @class = "form-control" })Code
}Code
elseCode
{TypeScript
@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" })Code
}Controller:
Code
public ActionResult Index(int? id)Code
{Code
VarsityContext VarsityDB = new VarsityContext();Code
Varsity.Models.Configuration configuration = new Varsity.Models.Configuration();Code
tryCode
{Code
TempData["Asset Inventory"] = "Asset Inventory";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_Type);Code
ViewBag.Conf_Type = basetypes;Code
}Code
catch (Exception ex)Code
{ }Code
return View(configuration);Code
}

Ehsan SajjadRank #512 · 4.8K reputationPosted Mar 2, 2017, 1:08 AM EST
Madhav SharmaRank #1,714 · 885 reputationPosted Mar 6, 2017, 10:26 PM EST