Hello, I am having trouble getting validation to work on my site. I have DataAttributes set but the client-side validation never fires.
Model:
View:
_Layout.cshtml
I notice there is no reference to the jquery.validate scripts, but when I add it to the header (like this):
I get errors when running the application:
Unhandled exception at line 1234, column 5 in
http://localhost:49715/Scripts/jquery.validate.js
0x800a138f - JavaScript runtime error: Unable to get property 'call' of undefined or null reference
Seems like validation should be pretty easy to get working, anyone have any suggestions?
Thanks!
Model:
public
class
Address
{
public
Guid? AddressId {
get
;
set
; }
[Required(ErrorMessage=
"City is required"
)]
[Display(Name =
"City"
)]
[MaxLength(25)]
public
string
City {
get
;
set
; }
public
bool
IsDefault {
get
;
set
; }
[Required]
[Display(Name =
"Address"
)]
[MaxLength(50)]
public
string
Line1 {
get
;
set
; }
[Display(Name =
""
)]
[MaxLength(50)]
public
string
Line2 {
get
;
set
; }
[Required]
[Display(Name =
"Name"
)]
[MaxLength(25)]
public
string
Name {
get
;
set
; }
[Required]
[MaxLength(2)]
public
StateDropdownViewModel State {
get
;
set
; }
[Display(Name =
"Zip Code"
)]
[MaxLength(10)]
public
string
ZipCode {
get
;
set
; }
}
View:
@using(Ajax.BeginForm("PersistShippingAddress", "Order", new AjaxOptions() { HttpMethod = "post" }))
{
<tr>
<td>City:</td>
<td>
@Html.EditorFor(model => model.ShippingAddress.City)
@Html.ValidationMessageFor(model => model.ShippingAddress.City)
</td>
</tr>
}
_Layout.cshtml
<
head
>
<
title
>@ViewBag.Title - My Telerik MVC Application</
title
>
<
link
href
=
"@Url.Content("
~/Content/Site.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2014.2.909/kendo.common.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2014.2.909/kendo.mobile.all.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2014.2.909/kendo.dataviz.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2014.2.909/kendo.metro.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2014.2.909/kendo.dataviz.metro.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
script
src
=
"@Url.Content("
~/Scripts/kendo/2014.2.909/jquery.min.js")"></
script
>
<
script
src
=
"@Url.Content("
~/Scripts/kendo/2014.2.909/kendo.all.min.js")"></
script
>
<
script
src
=
"@Url.Content("
~/Scripts/kendo/2014.2.909/kendo.aspnetmvc.min.js")"></
script
>
<
script
src
=
"@Url.Content("
~/Scripts/kendo.modernizr.custom.js")"></
script
>
</
head
>
I notice there is no reference to the jquery.validate scripts, but when I add it to the header (like this):
<
script
src
=
"@Url.Content("
~/Scripts/jquery.validate.js")"></
script
>
I get errors when running the application:
Unhandled exception at line 1234, column 5 in
http://localhost:49715/Scripts/jquery.validate.js
0x800a138f - JavaScript runtime error: Unable to get property 'call' of undefined or null reference
Seems like validation should be pretty easy to get working, anyone have any suggestions?
Thanks!