Ajax.BeginForm - Displaying Validation Errors -


Using the MVC project template in VS2008 (outside the box) I noticed the following:

    li>

    Register. Aspx form is specified.

     using  & lt;% (Html.BeginForm ()) {%>  
  1. Selecting the Register button without providing any account information shows it. Account creation was unsuccessful Please correct the errors and try again.

    • You must specify a username.
    • You must specify an email address.
    • You must specify a password of 6 or more characters.

  2. I have changed the Register.aspx form for this.

      & lt;% usage (Ajax.BeginForm ("Register", New AjaxOptions {HttpMethod = "Post"})) {% & Gt;  
  3. Selecting the registration button without providing account information does not show an error.

Q: How do I get error text to display when using Ajax.BegginForm?

Registry action and ideas must be modified to successfully implement AJAX form submission By default, In the case of error, this action only gives the related register.aspx view. The first step is to insert the verification summary inside the partial user control:

Validation SOCKS:

  & lt;% @ Control language = "C #" Inherits = "System. Web.Mvc.ViewUserControl "%> & Lt;% = Html Validation ("Account creation was unsuccessful. Please fix the errors and try again.")% & Gt;  

Then you include partial form inside the .aspx view:

   Form code here & lt;%}% & gt;  

And at the end you can modify the register verb:

  [AcceptVerbs (HttpVerbs.Post)] Public Action Register (string user name, string Email, String Password, Confirm String Keywords) {// ... Content left for clarity // If we have found a lot of this, then something has failed, make a new look again (request.isgexandest ()) {// If an AJAX request was made then Only validation errors were returned // Partial view instead of the entire page ("Verification"); } And {return view (); }}  

If the registration succeeds by default, the registration process only redirects to the home / index. You also need to modify this bit, because as you are requesting an AJAX request, redirection will not work. In the same way you can test if you are starting the action with asynchronous and will return some text that will indicate that the registration was successful. This text will be displayed as verification errors within the same div .


Update:

One last question - instead of the error messages bullet list, I have HTML. How do I get each control error message to render next to the control using the validity message ("....") method?

<% (Ajax.BeginForm "Register", blank, new AjaxOptions {HttpMethod = "POST", UpdateTargetId = "MyForm"}, new {id = "myForm"})) {%> & Lt;% HTML.RenderPartial ("RegisterForm"); & Gt%; & Lt;%}% & gt;

and presenting partially in your register verb:

  if (request.saaxxure ()) {return partial view ("register form") ; } And {return view (); }  

Comments