c# - There is no ViewData item of type IEnumerable -
i have viewmodel :
public class foundviewmodel { public string title { get; set; } public string description { get; set; } public int city { get; set; } public int subgroup { get; set; } public string address { get; set; } public datetime finddate { get; set; } }
and in view add 2 dropdown , fill in actionresult when call get:
var provinces = _provinces.selectall(); viewbag.provinces = new selectlist(provinces,"id","title",provinces.firstordefault().id);
and in view :
@html.dropdownlist("drpprovince", (selectlist)viewbag.provinces, new { @onchange="javascript:getcity(this.value);"})
but when click on button , post , getting error:
there no viewdata item of type 'ienumerable<selectlistitem>' has key 'drpprovince'
i found similar question on stackover flow can't know .
what's problem ? thanks.
what happens that, @ time of post , reload page show cities according selected province, not generating viewbag again.
the solution initialize viewbag again since lost after postback each call.
example.
public actionresult loadcities () { /* logic .... */ // here initialize viewbag again view know. return view (); }
Comments
Post a Comment