asp.net mvc - MVC 5 ajax partial form validation -


i'm using n ajax.beginform in typed view

within form have few panels hold model properties in turn use own models , editor templates.

i want post whole model ajax server @ end before doing i'm going panel panel , need validate each of them before progressing one.

how do partial (server side) validation (in controller action) of each panel , each model property on clicking next button?

can call somehow controller action on clicking each next button , how pass values of particular tab i'm validating? without refreshing page.

the models:

public class orderitem {     public int itemid { get; set; }     public itembasic basicdetails { get; set; }     public itemspecifics specification { get; set; } }  public class itembasic {     [required]     public string type { get; set; }      [required]     [stringlength(30)]     public string serialnumber { get; set; } } 

the view:

@model orderitem  @ajax.beginform(...) {     @html.antiforgerytoken()     @html.hiddenfor(x => x.itemid)     <div class="tab">         @html.editorfor(x => x.itembasics)         <input type="button" value="next" />     </div>     <div class="tab">         @html.editorfor(x => x.itemspecifics)         <input type="button" value="next" />     </div>     <input type="submit" value="add order" /> } 

the whole page more complicated that, simplified sake of question.

previously used partialviews each property (instead of editor templates) partialview parent model can't see property models when posting form @ end.

thank you

edit *****

also need load more data panels depending on user input/ selection in field , needs loaded server, in essence need call action on fields , populate other action result.

eg. in item specific panel user adds few items model list property, display list of rows in panel each can edited or deleted calling controller action.

with partialview performed action, added user input added new itemspecific item list , returned whole itemspecifics model partialviewresult given panel displaying list of added itemspecific items in panel.

public class itemspecifics {     public string name { get; set; }     public string description { get; set;}     public string ref { get; set;}     public ienumerable<itemspecifics> items { get; set;} } 

the easiest way validation client sided java script because it's complicated validate each panel seperated on server. can validation server sided , run checks in controller , if value not pass validation can return json result contain matching error message.

i hope answer helpful in way

for server sided validation try this:

if(validation 1 == false) {     errorlist.add("validation 1 error"); } if(validation 2 == false) {     errorlist.add("validation 2 error"); } if(validation 3 == false) {     errorlist.add("validation 3 error"); } if(errorlist.any) {     return jsonreturn(false, "you failed"); } return jsonreturn(true, "success!"); 

Comments