MVC3 Client side validation not working

后端 未结 3 1852
再見小時候
再見小時候 2020-12-15 00:09

I\'m using MVC3 with Razor.
I\'ve included the following in my _Layout.cshtml:



        
3条回答
  •  我在风中等你
    2020-12-15 00:27

    Try adding the following lines to your view.

    HtmlHelper.ClientValidationEnabled = true;
    HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
    

    Along with including jquery-1.4.4.js, jquery.validate.js, jquery.validate.unobtrusive.js

    I get it to work for my app but it seems not to kick in until I put in a bad value. For example

    [Required(ErrorMessageResourceType = typeof(Resources.WValidation), ErrorMessageResourceName = "TestCountRequired")]
            [Range(1, Int32.MaxValue, ErrorMessageResourceType = typeof(Resources.WValidation), ErrorMessageResourceName = "TestCountRange")]
            public int? TestCountThreshold { get; set; }
    

    then i put in a 0 on the front-end and after that client side validation works flawlessly. I would like for validation to work for initial blank text boxes... It seems incorrect for the validation to wait until there is an attempted bad value.

提交回复
热议问题