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?

mellis481
  • 4,332
  • 12
  • 71
  • 118
  • 2
    http://stackoverflow.com/a/14822755/1893261 Have a look at this post, let me know if it helps. – Shukhrat Raimov Sep 08 '14 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. – mellis481 Sep 08 '14 at 13:56

1 Answers1

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.

mellis481
  • 4,332
  • 12
  • 71
  • 118