I am using MVC's built in Remote Validation to validate a form on the server side.
My modelview looks like this:
[Required(ErrorMessage = "{0} is required")]
[Remote ("ValidateUserID", "MyController", AdditionalFields = "AccountType", ErrorMessage = "{0} cannot be found.")]
[Display(Name = "Account")]
public string Account { get; set; }
Typically my remote validation is nearly instant, however rarely it gets caught up and will take nearly 1 or 2 seconds to finish. This causes a problem with my form.
Some of my other fields are based on whether or not the Account field is valid or not.
So I need to force this remote validation to run synchronously.
Before you say it, I know it freezes the page. But I am okay with this. If you guys can give me any better ideas that is also greatly appreciated.
Thanks!
This is controlled by the
remote: function(value, element, param) {method in thejquery.validate.jsfile, which makes an ajax call and uses the defaultasync: true.You could modify this file (add
async: false,) but I would not recommend that. Instead you could remove the[Remote]and then handle the.change()event of the input to make your own ajax call to the controller withasync: false,.