This is a migrated thread and some comments may be shown as answers.

Can't get validation to work

1 Answer 208 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Cool Breeze
Top achievements
Rank 1
Cool Breeze asked on 19 Oct 2014, 09:16 PM
Hello, I am having trouble getting validation to work on my site. I have DataAttributes set but the client-side validation never fires.

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!

1 Answer, 1 is accepted

Sort by
0
Cool Breeze
Top achievements
Rank 1
answered on 19 Oct 2014, 10:07 PM
I just found this article which was exactly what I needed:

http://docs.telerik.com/kendo-ui/aspnet-mvc/validation

Thanks!
Tags
Validation
Asked by
Cool Breeze
Top achievements
Rank 1
Answers by
Cool Breeze
Top achievements
Rank 1
Share this question
or