asp.net mvc - MVC Ajax BeginForm validation -


i have bootstrap modal makes insert. using ajax beginform , have problem validation. normal validation like: required fields works great. problem have server validation , when goes controller , not pass custom validation tried return partialview model or json not able trigger validation on modal. googled lot , not able solve problem.

here code

public class contactdto {     public decimal idcontact{ get; set; }     public decimal? counterpartyid { get; set; }     public string name { get; set; }     public string address { get; set; }     public string city { get; set; }    } 

controller:

[httppost] [validateantiforgerytoken] public jsonresult editcontact(contactdto contact) {     if (customvalidation(code) && modelstate.isvalid)     {         _dbmanager.createcode(code);          //return redirecttoaction("details", "counterparties", new { id = code.codecounterpartyid });         return json(new { data = "ok" }, jsonrequestbehavior.allowget);     }      return json(new { data = "nok" }, jsonrequestbehavior.allowget); } 

modal ajax:

@using system.globalization @model updatetabs.models.contactdto  <div id="editcontactmodaldiv" class="modal fade" role="dialog">     <div class="modal-dialog modal-lg">      .......          @using (ajax.beginform("editcontact", "home", new ajaxoptions { httpmethod = "post", onsuccess = "validatekeys"}, new { id = "formcreatecontact" }))         {             @html.antiforgerytoken()             @html.validationsummary(false, "", new { @class = "text-danger" })              ......              @html.textboxfor(m => m.name)             <br/>             @html.validationmessagefor(m => m.name)              ......               }         .......      </div> </div>       

and jquery part:

function validatekeys(result) {     if (result.ok) {         $('#createcodemodaldiv').modal('hide');     } else {          alert("model invalid !");         $('#createcodemodaldiv').modal('show');     } } 

and until here working, after here don't know trigger validation message for.

any please? thanks


Comments

Popular posts from this blog

Sass watch command compiles .scss files before full sftp upload -

filehandler - java open files not cleaned, even when the process is killed -

gridview - Yii2 DataPorivider $totalSum for a column -