1

This MSDN article talks about using remove validation to validate a single value....

http://msdn.microsoft.com/en-us/library/gg508808%28v=vs.98%29.aspx

In particular, the model properties are attributed so that remove validation is invoked ...

public class CreateUserModel : EditUserModel {
    [Required]
    [StringLength(6, MinimumLength = 3)]
    [Remote("IsUID_Available", "Validation")]
    [RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed.")]
    [Editable(true)]
    public override string UserName { get; set; }
}

What I want to achieve is remote validation where a number of fields are taken into account. For example I may want to submit two or three fields in an Ajax manner and get back an overall validation result.

How can this be achieved?

2
  • If you need to validate against multiple values aren't you validating the form rather than just a field? Are these multiple values part of the form? Commented Dec 21, 2011 at 13:27
  • Yes they are part of the same form. Commented Dec 21, 2011 at 15:43

1 Answer 1

5

You could set the AdditionalFields property of the [Remote] attribute in order to have other property values sent to the action.

[Remote("IsUID_Available", "Validation", AdditionalFields = "Email")]
public override string UserName { get; set; }

and then inside your controller action:

public ActionResult IsUID_Available(string username, string email)
{
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.