Model Validation in ASP.NET MVC -


i not getting validation messages? idea how resolve? please take @ view, model, , controller code below. attached js files maybe im missing files?

@model mvcapplication1.models.assesment <link href="../../content/site.css" rel="stylesheet" type="text/css" /> <script src="../../scripts/jquery.validate.min.js" type="text/javascript"></script> <script src="../../scripts/jquery.validate.min.js" type="text/javascript"></script>  @using (html.beginform()) {        @html.textboxfor(m => m.name)    @html.validationmessagefor(m=>m.name,"*hello")  } <input type="submit" value="submit" /> 

using system; using system.collections.generic; using system.componentmodel; using system.web.mvc; using system.componentmodel.dataannotations;  namespace mvcapplication1.models {    public class assesment    {        [required]     public string name { get; set; }     } }  public class registercontroller : controller {      [httpget]     public actionresult index()     {         return view();     }       [httppost]      public actionresult index(assesment assesment)      {          return view();      } } 

your <input type="submit"> should inside form.

also, should pass invalid model view when handling post

[httppost] public actionresult index(assesment assesment) {     return view(assesment); } 

by way, typical httppost action looks this:

[httppost] public actionresult index(assesment assesment) {     if( modelstate.isvalid )     {         // handle post data (write db, etc.)         //...         // redirect new page         return redirecttoaction( ... );     }      // show same view again, time validation errors     return view(assesment); } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -