Below is the error on my view page.
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CategoryList
I had tried lots of things to solve this problem but I can't got a perfect solution about my question.
What I have tried:
model code and the model class name is admin.
public string usertype { get; set; }
Controller code(generate the option for dropdown list):
public ActionResult Addnewuser()
{
List<SelectListItem> CategoryList = new List<SelectListItem>();
CategoryList.Add(new SelectListItem { Text = "Client", Value = "Client" });
CategoryList.Add(new SelectListItem { Text = "Consultant", Value = "Consultant" });
ViewBag.categoryList = CategoryList;
return View("Adminhome");
}
View page:
@Html.DropDownList("CategoryList", (IEnumerable<SelectListItem>)ViewBag.categoryList, "Please Select", new { @class = "form-control enquirybox", id = "drpdwncategory" })