Can't get validation to work

2 posts, 0 answers
  1. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 19 Oct 2014 Link to this post

    Hello, I am having trouble getting validation to work on my site. I have DataAttributes set but the client-side validation never fires.


    public class Address
           public Guid? AddressId { get; set; }
           [Required(ErrorMessage="City is required")]
           [Display(Name = "City")]
           public string City { get; set; }
           public bool IsDefault { get; set; }
           [Display(Name = "Address")]
           public string Line1 { get; set; }
           [Display(Name = "")]
           public string Line2 { get; set; }
           [Display(Name = "Name")]
           public string Name { get; set; }
           public StateDropdownViewModel State { get; set; }
           [Display(Name = "Zip Code")]
           public string ZipCode { get; set; }


    @using(Ajax.BeginForm("PersistShippingAddress", "Order", new AjaxOptions() { HttpMethod = "post" }))
            @Html.EditorFor(model => model.ShippingAddress.City)
            @Html.ValidationMessageFor(model => model.ShippingAddress.City)


        <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/")" 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>

    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

    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?

  2. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 19 Oct 2014 in reply to Cool Breeze Link to this post

    I just found this article which was exactly what I needed:

Back to Top