ASP.NET MVC 4 Validation Errors not being displayed -


i'm using asp.net mvc 4.

i don't think modelstate being passed properly,

controller action: home/enrolresult follows:

[httppost] public actionresult enrolresult(uploadmodel model) {     if (modelstate.isvalid)     {         // codes in here         return view();     }     return view("~/views/home/index", model); } 

view: home/index, follow:

@using (html.beginform("enrolresult", "home", formmethod.post, new { enctype = "multipart/form-data" })) {      @html.validationsummary()      @html.labelfor(m => m.firstname)     @html.textboxfor(m => m.firstname)      @html.labelfor(m => m.surname)     @html.textboxfor(m => m.surname)      <li data-role="fieldcontain">         <input type="submit" value="enrol" />     </li> } 

when enter details correctly functions correctly , displays enrolresult view.

when enter details incorrectly returns home/index doesn't display validation error of form wasn't entered.

the model set correctly have tested changed enrolresult action index action , validation error displayed correctly, used view(model) meaning modelstate wouldn't have passed i'm trying in case.

is way i'm doing correct? i've seen people use tempdata thought method meant work?

validation message helpers missing:

@using (html.beginform("index", "home", formmethod.post, new { enctype = "multipart/form-data" })) {      @html.validationsummary()      @html.labelfor(m => m.firstname)     @html.textboxfor(m => m.firstname)     @html.validationmessagefor(m => m.firstname)      @html.labelfor(m => m.surname)     @html.textboxfor(m => m.surname)     @html.validationmessagefor(m => m.surname)      <li data-role="fieldcontain">         <input type="submit" value="enrol" />     </li> } 

edit:

if don't want use validationmessagefor believe need use different overload of html.validationsummary(false). if remember correctly default behavior of validationsummary hides property-level errors avoid duplication.


Comments