There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'categoryId'.
This is my code
Controller:
[HttpGet]
public ActionResult AddNewProduct()
{
ViewBag.Category = new List<SelectListItem>
{
new SelectListItem{Text="DELL",Value="1"},
new SelectListItem{Text="HP",Value="2"},
new SelectListItem{Text="APPLE",Value="3"},
new SelectListItem{Text="ACER",Value="4"},
new SelectListItem{Text="LENOVO",Value="5"},
new SelectListItem{Text="SAMSUNG",Value="6"},
new SelectListItem{Text="ASUS",Value="7"}
};
return View("AddNewProduct");
}
//Razor View
@Html.DropDownListFor(
m => m.categoryId,
@ViewBag.Category as List<SelectListItem>,
new { @class="dropdownList", style = "width:25%;" })
What I have tried:
http://www.asp.net/mvc/overview/older-versions/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc