asp.net mvc - My partial View is not showing error on validation and also on error my both view is getting opened up -


i facing problem in validation in 2 of partial view

_partiala.cshtml

@model demo3.models.modela     @using (html.beginform("test", "home"))    {  <h2>_partiala</h2> <div>      @html.editorfor(m => m.employeeid)        @html.validationmessagefor(m => m.employeeid)  </div> <div>      @html.editorfor(m => m.employeename)      @html.validationmessagefor(m => m.employeename)  </div>  <input class="mainbutton" type="submit" value="test"/><br />  } 

and partial view this

_partialb.cs.html

 @model demo3.models.modelb       @using (html.beginform("createagreement", "home"))             {  <h2>_partialb</h2> <div>     @html.editorfor(m => m.comapny)     @html.validationmessagefor(m => m.comapny) </div> <div>     @html.editorfor(m => m.fisacalyear)     @html.validationmessagefor(m => m.fisacalyear)  </div>   <input class="mainbutton" type="submit" value="createagreement"/><br />  } 

this controller code

 [httppost]     public actionresult createagreement(modelb modelb)     {         if (modelstate.isvalid)         {             return view("start", modelb);         }         return view("start", modelb);     }     [httppost]     public actionresult test(modela modela)     {         if (modelstate.isvalid)         {             return view("start", modela);         }         return view("start", modela);     }     public actionresult start()     {         return view();     }     public actionresult firstview()     {         modela obja = new modela();         return partialview("_partiala", obja);     }     public actionresult secondview()     {         modelb objb = new modelb();         return partialview("_partialb", objb);     } 

now not getting error message on click of button..and thing..is both view getting opened up..on click of button..how prevent that?

to validate form check these steps :

1) partial view set layout null :

@{     layout = null; } 

2) add these scripts before form :

<script src="@url.content("~/scripts/jquery.validate.min.js")"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")"></script>  @using (html.beginform("createagreement", "home"))  { 

3) add html validation :

@using (html.beginform("createagreement", "home"))  {      @html.validationsummary(true) 

4) if have annotation model , error message works.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -