1

I have the following HTML in my view:

@model PatientLookupModel
@if (Model.IsModelInvalid)
{
    @Html.ValidationSummary(false, Model.Resources.InvalidFormMessage)
}

@using (Html.BeginForm("Lookup", "Patient", FormMethod.Post, new { role = "form" }))
{
    @Html.Label(Model.Resources.PatientFirstNameLabel)
    @Html.TextBoxFor(m => m.PatientFirstName, new { @class = "form-control" })
}

My model looks like this:

using RESOURCES = AppResources.Resources;    
namespace Models
{
    public class PatientLookupModel
    {
        [Required(ErrorMessageResourceType = typeof(RESOURCES), ErrorMessageResourceName = "Patient_Lookup_PatientFirstNameRequiredMessage")]
        public string PatientFirstName { get; set; }
    }
}

My BundleConfig looks like this:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/lib/jquery-{version}.js",
                    "~/scripts/lib/jquery.unobtrusive*",
                    "~/Scripts/lib/jquery.validate*",
                    "~/Scripts/lib/jquery.maskedinput.js"));

The form itself works as expected. When the first name is not entered, the page reloads with the validation summary populated. The problem is that when you type something in the first name input and then it loses focus, an exception is thrown in the browser console:

enter image description here

data is undefined.

Any ideas?

2
  • 2
    stackoverflow.com/a/14822755/1893261 Have a look at this post, let me know if it helps. Commented Sep 8, 2014 at 13:02
  • @ShukhratRaimov: I had previously tried loading an earlier version of jquery (I'm using 1.11.1) and noticed that it had different behavior. Using 1.11.1, it will actually postback, but versions < 1.9 just apply an error class to the elements and put them in focus. I'm not sure this behavior is acceptable. Commented Sep 8, 2014 at 13:56

1 Answer 1

1

Removing the reference to jquery.unobtrusive-ajax.js and jquery.validate* is actually what I wanted to do. For some reason (perhaps the reason identified by @ShukhratRaimov), client-side validation breaks when I'm using jquery 1.11.1. I actually don't even want client-side validation - I want the app to post back and display model errors.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, Jquery.validate clashes with Microsofts unobtrusive validation. Good catch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.