this is my controller action
public ActionResult AddNewPost(string subName)
{
ViewBag.CategoryID = new SelectList(from c in db.Categories where c.Status == true select c, "CategoryID", "CategoryName");
return View();
}
in view i have populated dropdown as
<td>
@Html.DropDownList("CategoryID", "-- Select --")
</td>
but when i try to access the drop down value in controller i get this error "There is no ViewData item of type 'IEnumerable' that has the key 'CategoryID'."
Try this:
Try This:
In Database Make CategoryId Allow nulls and in Model File Make it Has Nullable Ex: In Model
view should be like this