Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Joshua Lemli 52 posts 234 karma points
    Feb 27, 2018 @ 20:09
    Joshua Lemli

    CompareAttribute data annotation causes jQuery error with `BeginUmbracoForm` and client validation

    I am using some code (like the following) to create a form:

    var someModel = new SomeModel();
    using (Html.BeginUmbracoForm<SomeController>("SomeMethod"))
        @Html.ValidationSummary("someModel", true)
            @Html.LabelFor(m => someModel.RandomProperty)
            @Html.PasswordFor(m => someModel.RandomProperty)
            @Html.ValidationMessageFor(m => someModel.RandomProperty)

    It works, but jQuery throws an error:

    Uncaught Error: Syntax error, unrecognized expression: :input[name=someModel.RandomProperty]

    The property that it is referencing looks like this:

            [Display(Name = "Some Prop")]
            [Compare("OtherProp", ErrorMessage = "These should match.")]
            public string RandomProperty { get; set; }

    Removing the Compare data attribute "fixes" the error, but I want to be able to use this attribute!

    I will note that nothing breaks... there's just an error in the JS-console. The property is properly "compared" and my c# code keeps-on-goin'.

Please Sign in or register to post replies

Write your reply to: