Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 81933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:32:16+00:00 2026-05-10T21:32:16+00:00

I have an MVC view with a form built with the Ajax.BeginForm() helper method,

  • 0

I have an MVC view with a form built with the Ajax.BeginForm() helper method, and I’m trying to validate user input with the jQuery Validation plugin. I get the plugin to highlight the inputs with invalid input data, but despite the invalid input the form is posted to the server.

How do I stop this, and make sure that the data is only posted when the form validates?

My code


The form:

<fieldset>     <legend>leave a message</legend>         <% using (Ajax.BeginForm('Post', new AjaxOptions            {                UpdateTargetId = 'GBPostList',                InsertionMode = InsertionMode.InsertBefore,                OnSuccess = 'getGbPostSuccess',                OnFailure = 'showFaliure'            }))            { %>         <div class='column' style='width: 230px;'>             <p>                 <label for='Post.Header'>                     Rubrik</label>                 <%= Html.TextBox('Post.Header', null, new { @style = 'width: 200px;', @class='text required' }) %></p>             <p>                 <label for='Post.Post'>                     Meddelande</label>                 <%= Html.TextArea('Post.Post', new { @style = 'width: 230px; height: 120px;' }) %></p>         </div>         <p>             <input type='submit' value='OK!' /></p>     </fieldset> 

The JavaScript validation:

$(document).ready(function() {     // for highlight     var elements = $('input[type!='submit'], textarea, select');     elements.focus(function() {         $(this).parents('p').addClass('highlight');     });     elements.blur(function() {         $(this).parents('p').removeClass('highlight');     });      // for validation     $('form').validate();    }); 

EDIT: As I was getting downvotes for publishing follow-up problems and their solutions in answers, here is also the working validate method…

function ajaxValidate() {     return $('form').validate({     rules: {         'Post.Header': { required: true },         'Post.Post': { required: true, minlength: 3 }     },     messages: {         'Post.Header': 'Please enter a header',         'Post.Post': {             required: 'Please enter a message',             minlength: 'Your message must be 3 characters long'             }         }     }).form(); } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:32:16+00:00Added an answer on May 10, 2026 at 9:32 pm

    Try adding an OnBegin callback to the AjaxOptions and return the value of $(‘form’).validate().form() from the callback. Looking at the source it appears that this should work.

    function ajaxValidate() {    return $('form').validate().form(); }  <% using (Ajax.BeginForm('Post', new AjaxOptions        {            UpdateTargetId = 'GBPostList',            InsertionMode = InsertionMode.InsertBefore,            OnBegin = 'ajaxValidate',            OnSuccess = 'getGbPostSuccess',            OnFailure = 'showFaliure'        }))        { %> 

    EDIT updated with correct callback name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The theme function you need to override is ccktype_node_form, not… May 11, 2026 at 12:21 pm
  • added an answer Try ant4eclipse. May 11, 2026 at 12:21 pm
  • added an answer It depends on the context. In a general purpose library,… May 11, 2026 at 12:21 pm

Related Questions

I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach
I have an application, built using MVC, that produces a view which delivers summary
Simple enough, it would seem, but it turns out not to be - mainly
Caution: This question is over nine years old! Your best option is to search

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.