Reputation: 4168
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:
data
is undefined.
Any ideas?
Upvotes: 1
Views: 603
Reputation: 4168
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.
Upvotes: 1