I am using remote validation to check the availability of username during registration for my asp.net mvc 3 applicaion (C#).
I am using MVC remote Attribute validation as:
[Remote("IsUserNameAvailable", "User")]
public string UserName { get; set; }
When I return this:
return Json(true, JsonRequestBehavior.AllowGet);
Then I want to perform something like set the hidden field value, which is return from action or show green icon image. And i want to also return ID with true.
How to achieve this things ?
In short, I want to do something on success.
One way to achieve that is to add a custom HTTP response header from the validation action:
Now on the client we obviously have a standard form and an input field for the username:
and now the last piece of the puzzle is to attach a
complete
handler to theremote
rule on the username field: