c# - asp.net mvc 3 model binding dropdown -
i have view form. on form have textboxes , 2 dropdownlists.
this viewmodel.
public class newapplicationviewmodel { public applicationdata application { get; set; } //selectlists public selectlist questionnaires { get; set; } public selectlist jobs { get; set; } }
the applicatoindata class looks this
public class applicationdata { [hiddeninput(displayvalue = false)] public guid id { get; set; } [required] public applicantdata applicant { get; set; } [required] public questionnairedata questionnaire { get; set; } [required] public jobdata job { get; set; } public string pdf { get; set; } }
the "questionnaire" , te "job" have selected dropdownlists. how can bind selected value in dropdown object in "applicationdata"? complete, controller action hande form submit.
[httppost] public actionresult newapplication([bind(prefix="application")]applicationdata model) { var application = mapper.map<applicationdata, application>(model); _applicationrepository.add(application); _session.commit(); return view(); }
thanks
@html.dropdownlistfor( x => x.application.questionnaire.id, model.questionnaires ) @html.dropdownlistfor( x => x.application.job.id, model.jobs )
Comments
Post a Comment