Madhav Sharma

Madhav Sharma

  • 889
  • 899
  • 39.3k

getting error in mvc dropdown

Nov 1 2019 5:12 AM
I am getting error "System.InvalidOperationException: 'There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'ddlweb'. "
 
public ActionResult GetWebVersions()
{
ViewBag.ddlwebversion = MS.GetWebVersion();
return View("Version");
}
  
public dynamic GetWebVersion()
{
using (LystenEntities db = new LystenEntities())
{
//var weblist = db.WebVersions.Where(x => x.Status == "Current").OrderBy(x => x.Id).ToList();
return new SelectList(db.WebVersions.OrderBy(x => x.Id).ToList(), "Id", "Version");
}
}
 
 
<div class="form-group form-group-default">
<input type="hidden" id="hdnId" />
<label>Category Name</label>
@*@Html.DropDownList("ddlwebversion", (SelectList)ViewBag.ddlwebversion, "--- Select ---", new { @class = "form-control " })*@
@Html.DropDownList("ddlwebversion", (IEnumerable<SelectListItem>)ViewBag.ddlwebversion, "----Select---", new { @class = "form-control " })
</div>
 
 

Answers (1)