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

  • Home
  • SEARCH
  • 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 8331139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:19:42+00:00 2026-06-09T02:19:42+00:00

I am trying to implement optional client side validation using ASP.NET MVC 4, unobtrusive

  • 0

I am trying to implement optional client side validation using

  • ASP.NET MVC 4,
  • unobtrusive jQuery validation,
  • unobtrusive ajax

This works fine

Following pictures show what I mean with optional client side validation:
The only one field on my form is expected to contain email, so there is an email validator attached to it.

enter image description here

Now we click on save. Because our text “name@doamin” is not a valid email the validation summary gets displayed. Together with validation summary we are unhiding “Save anyway” button.

enter image description here

This second button is a normal submit button just having class="cancel". This instructs jQuery.validate.js script to skip validation when submitting using this button.

Here is the code snippet of the view:

@using (Html.BeginForm())
{
    <div>
        <input data-val="true" data-val-email="Uups!" name="emailfield" />
        <span class="field-validation-valid" data-valmsg-for="emailfield" data-valmsg-replace="false">*</span>
    </div>

    <input type="submit" value="Save" />
    @Html.ValidationSummary(false, "Still errors:")
    <div class="validation-summary-valid" data-valmsg-summary="true">
        <input type="submit" value="Save anyway" class="cancel" />
    </div>
}

These all works fine.

The problem

The second submit button – “Save anyway” stops working as expected if I switch over to Ajax form. It just behaves like the the normal one and prevents submit until validation succeeds.

Here is the code snippet of the “ajaxified” view:

@using (Ajax.BeginForm("Edit", new { id = "0" },
        new AjaxOptions
            {
                HttpMethod = "POST",
                InsertionMode = InsertionMode.Replace,
                UpdateTargetId = "ajaxSection",
            }))
{
    <div>
        <input data-val="true" data-val-email="Uups!" name="emailfield" />
        <span class="field-validation-valid" data-valmsg-for="emailfield" data-valmsg-replace="false">*</span>
    </div>

    <input type="submit" value="Save" />
    @Html.ValidationSummary(false, "Still errors:")
    <div class="validation-summary-valid" data-valmsg-summary="true">
        <input type="submit" value="Save anyway" class="cancel" name="saveAnyway" />
    </div>
}

I have debugged jQuery.validation.js to find out what is the difference, but failed.

Qustion

Any ideas to fix or workaround the problem and let the ajax form behave as intended are welcome.


Addendum

To have a client side validation is an absolute must. Server side validation is not an option. Aside from higher traffic (this sample is a simplification – the real form contains much more fields) and latency, there is one thing which server side validation would not do: client side validators highlight erroneous fields on lost focus. It means you have a feedback as soon as you tab to the next field.

  • 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-09T02:19:43+00:00Added an answer on June 9, 2026 at 2:19 am

    That’s a known limitation of Microsoft’s unobtrusive ajax script. You could modify it to fix the bug. So inside the jquery.unobtrusive-ajax.js script replace the following on line 144:

    $(form).data(data_click, name ? [{ name: name, value: evt.target.value }] : []);
    

    with:

    $(form).data(data_click, name ? [{ name: name, value: evt.target.value, className: evt.target.className }] : []);
    

    In addition we are passing the class name to the handler so that it can decide whether it should trigger client side validation or not. Currently it always triggers validation no matter which button was clicked. And now on line 154 we modify the following test:

    if (!validate(this)) {
    

    with:

    if (clickInfo[0].className != 'cancel' && !validate(this)) {
    

    so that client side validation is no longer triggered if a submit button with class name cancel was used to submit the form. Another possibility is to scrape the jquery.unobtrusive-ajax.js script and replace your Ajax.BeginForm with a standard Html.BeginForm that you could unobtrusively AJAXify using plain old jQuery.

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

Sidebar

Related Questions

I'm trying implement a bracket in my program (using C#/.NET MVC) and I am
I'm trying to implement a service with Multiple Optional Parameters using ServiceStack.Net At the
I'm trying to molularize my ASP.NET MVC application by moving each Area into their
I'm trying to implement the GetHttpContext function from HtmlHelperTest.cs in VB.NET using Rhino Mocks,
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement a Search-Function using c++ and libpqxx. But I've got the
I have an existing asp.net c# application for which I'd like to implement a
trying to implement a multiplayer. Using the sample from Game Center - Sending and
Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however
I'm trying to implement optional parameters in a stored procedure that I have but

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.