Getting Error There is no ViewData item of type IEnumerableSelectListItem that has the key State
public class user_detail
{
public int User_id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public Nullable<long> Phone { get; set; }
public IEnumerable<SelectListItem> State { get; set; }
public int State_id { get; set; }
public string City { get; set; }
public string Address { get; set; }
public string Password { get; set; }
public string User_Type { get; set; }
public Nullable<int> Org_id { get; set; }
}
Controller action
var stat = db.States.ToList();
//Assigning generic list to ViewBag
List<SelectListItem> Statlist = new List<SelectListItem>();
foreach (State item in stat)
{
Statlist.Add(new SelectListItem
{
Text = item.State1,
Value = item.State_id.ToString()
});
}
ViewBag.States = Statlist;
return View();
data saved in database but this error always come