Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc 3 - ajax form submit and validation
    primarykey
    data
    text
    <p>I am sorry if this has been asked already, but I have been looking for sometime but all I have found are rather old posts (mvc1, mvc2). I have a form which I would like to submit via Ajax.</p> <p><a href="https://stackoverflow.com/questions/298691/asp-net-mvc-ajax-form-with-jquery-validation">This</a> looks like it would work but does not cover server side validation.</p> <p>1) I am unsure if I should use the <code>AjaxHelper.BeginForm</code> or use raw jquery calls <code>($.ajax)</code>? What is the recommended approach here?</p> <p>2) How do I handle client and server side validation? I am hoping the mvc framework provides a built in mechanism for dealing with this? There are some validations which I am only doing server side. Would using a <code>ValidationSummary</code> still work here?</p> <p>I am using asp.net mvc3/razor with unobtrussive javascript validation.</p> <p>Thank you!</p> <p><strong>Edit: (as requested by Bobby B below).</strong> This was added months after asking the question as a user wanted to know how to use AjaxHelper</p> <p>This is the javascript code I used:</p> <pre><code>&lt;script type="text/javascript"&gt; function ajaxValidate() { return $('form').validate().form(); } function getGbPostSuccess(ajaxContext){ // .... it is not necessary to do anything here. } function showFaliure(ajaxContext){ // handle failure } </code></pre> <p></p> <p>HTML snippet:</p> <p> </p> <pre><code>@using (Ajax.BeginForm("Index", "Home", new AjaxOptions { UpdateTargetId = "form1", InsertionMode = InsertionMode.Replace, OnBegin = "ajaxValidate", OnSuccess = "getGbPostSuccess", OnFailure = "showFaliure" })) { </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload