Kevin Kevin - 14 days ago 4x
ASP.NET (C#) Question

C# MVC Dropdownlist no ViewData item

I am having an issue with a dropdownlist I have in a


Basically get the following error
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Status'.

Here is my
method inside the controller

public ActionResult Status()
List<SelectListItem> Status = new List<SelectListItem>();

Status.Add(new SelectListItem { Text = "Open", Value = "1" });
Status.Add(new SelectListItem { Text = "Closed", Value = "2" });
Status.Add(new SelectListItem { Text = "Delete", Value = "3" });

ViewData["Status"] = Status;

return View();

Partial View where I call the select list

@Html.DropDownList("Status", ViewData["Status"] as SelectList)

And then I call the partial view from my main view as follows


I am just not sure why its giving the above error. I took at look at this mvc dropdownlist no ViewData item and still not able to rectify the issue?


As per @MikeDebela solution my Status Action Item was never been called. So used the following syntax to call the Action directly



When you use Partial helper, the runtime looks for the view and renders a string (your action will never executed). RenderAction on the other hand, executes the action and displays the result. So use: