asp.net mvc 3 - MVC3 Dropdown repopulates fine even on error postback, but suggestion on how to make it efficient - without introducing error -
i can't post code @ moment on road , out of office. here code simplified. don't think have syntax issue such - think need clarification or, pointer. model: [validaton attribute] class data { [required] int xx .. } viewmodel: class vm { selectitem items; int itemid; data dt = new data(); public vm { items =... load db... } } view @textbox xx (etc) @dropdownfor(vm.itemid, vm.items controller void index { vm vm = new vm(); //i default items here works - nice form loaded. return view(vm); } [post] void index(vm stuffposted) { if modelstate.ok)( { good. direct page redirect action } else { return view(stuffposted) //this problem case need efficiency } problem the form loads fine index method. on postback submit, id comes correctly in itemid. if there error - modelstate sends view...and selection list(s) in place, selections. oh joy! but, in postback method, vm stuffposted instance class invokes constructor , there (ex...