In the below code I cannot pass the username to the remote validation function:
public string UserName { get; set; }
public class Numbers
{
[Display(Name = "Additonal Numbers")]
[Remote("NumberExists", "Account", AdditionalFields = "UserName", ErrorMessage = "Serial is already taken.")]
public string additionalNumbers { get; set; }
}
public List<Numbers> NumberList { get; set; }
This is a simple example but I would like to pass additional fields from the same model within a list but I cant seem to access anything outside the scope of the public class.
Do I need to pass the rest of the model into the list in some way to achieve this or am I doing something wrong here?
The
AdditionalFieldsparameter in the remote validation attribute need to be in the same class as the object being validated...edit..
..edit after comments..
It looks like what you want to do is validate that all the numbers are unique for a Username. Try this:
In your NumberExists Action take a List of Strings rather than only 1 string. This will let you validate your whole array all at once.