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 8697297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:29:27+00:00 2026-06-13T01:29:27+00:00

I am using MVC 3 and razor in Visual Studio 10 with client side

  • 0

I am using MVC 3 and razor in Visual Studio 10 with client side unobtrusive validation. I have a requirement to offer the user an opportunity to save a form fs some of the required fields are missing. The submit is with an Ajax.bgein form structure.

I have the following JavaScript to catch the submit event.

$(document).ready(function () {

$('#submit-11').click(function (event) {

    var validator = $("#form0").validate();

    if (!$("#form0").valid()) {
        // for partial save needs either ID number
        // or family name and date of birth
        var NameExists = true;
        var DateOfBirthExists = true;
        var IDNumberExists = true;

        if (validator.errorMap["model.FamilyName"]) { NameExists = false; }
        if (validator.errorMap["model.DateOfBirth"]) { DateOfBirthExists = false; }
        if (validator.errorMap["model.IDNumber"]) { IDNumberExists = false; }

        if (IDNumberExists || (NameExists && DateOfBirthExists)) {
            if ($("#model_PartialSave").attr('checked')) {
                //  partial save has been requested
                alert("saving");
                return true;    // AJAX save is NOT triggered
            }
            $("#AgreePartialSave").show();
            $("#model_PartialSave").removeAttr('checked');

        }
        return false;
    }
    return true;    // AJAX save IS triggered
});

});                    //document ready end

The logic seems to be correct – I have traced this in firebug – and the alert is triggered but the AJAX submit call does not happen. If the form is valid the AJAX submit call happens.

I have also tried event.preventDefault(); but that prevents any save happening.

I have also traced this in firebug and all the correct calls seem to be being made.

Any help gratefully received.

UPDATE

It seems that this might be a limitation in the Microsoft Ajax library. See this link for the details and a work around.

  • 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. Editorial Team
    Editorial Team
    2026-06-13T01:29:28+00:00Added an answer on June 13, 2026 at 1:29 am

    I believe what you need to intercept is the form’s submit event, not the submit button’s click event. What’s happening (I suspect) is that, since the validation framework still considers your form to be invalid, it’s not submitting it, even though you’re letting the click event go through with your return true.

    There’s an example here of running javascript after validation has completed but before the actual post.

    $(function() { 
        $('#form0').submit(function() { 
            if (!$(this).valid()) { 
                // do your thing
                return true; 
            } 
        }); 
     }); 
    

    ETA: having read your reply, I wonder whether the problem isn’t that the validation framework considers your page invalid, and you’re attempting to override its conclusion and submit anyway. In that case, the code I provided would never execute because the submission would never happen.

    I would suggest trying this: remove the Required attributes from the properties in the model that correspond to the 3 input fields, and move your checking logic into the submit function, as I suggested. But rather than saying, if(!$(this).valid()), you would only execute the code if the form was otherwise valid.

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

Sidebar

Related Questions

I'm using Visual Studio 2010 / C# 4.0 / MVC 3 / Razor /
I am using Visual Studio 2010 / ASP.net MVC 3 with the Razor View
I have just started with my project using MVC and Razor. Now I am
Using a Telerik Grid with ASP.NET MVC 3 Razor engine. When a user selects
I have this code in mvc 3 razor @using (Html.BeginForm(MyAction, MyController)) { <input type=text
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I create a ASP.net MVC 4 project by using Visual Studio 2010 IDE. I
I am developing a web site using MVC 3 razor, in which I have
I have a project that I am developing using MVC 3 using Razor views.
Using MVC Razor I have a very simple test. The logger writes messages to

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.