Asp.Net MVC - JQuery remote validation
I got the following JQuery validation script :
<script type="text/javascript">
$(document).ready(function() {
    $("#myForm").validate({
        rules: {
            "Content": {
                required: true,
                rangelength: [20, 1000],
                remote: {
                    url: "/RemoteValidation/IsValidContent",
                    timeout: 2000,
                    type: "post"
                }
            }
        },
        messages: {
            "Content": {
                required: "* ...A",
                rangelength: "* ...B",
                remote: "* ...C"
            }
        }
    });
});
And the following controller :
public class RemoteValidationController : Controller
    {
        [HttpPost]
        public virtual JsonResult IsValidContent(MyObject object)
        {    
            return new JsonResult
            {
                Data = true
            };
        }
}
It's only for test purpose, its always return true.
The problem I got is the following. I s开发者_开发知识库ee the error message (...C) that appears for 1 second and that disapear...
I don't know how to solve that...
Why it appears... it's should never appear...
UPDATE
The problem only appear if I write really quickly in the textarea. If I write slowly, it's doesn't appear. My guess is that between my typing, the validation haven't no time to validated, and by default, it's show the error ?
Anyway, I can change this behavior ?
You could disable validation when typing but only before submitting the form:
$('#myForm').validate({
    onfocusout: false,
    onkeyup: false,
    ...
});
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论