Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Issue: UpForGrabs: Validation should honor member field in ValidationResult [362]

$
0
0
Reported by a user:

The problem I am having is with models like:

// the view model
public class RegisterModel : IValidatableObject
{

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (somethingIsWrong)
yield return new ValidationResult("Something went wrong", new[] { "Field1" });

if (somethingElseIsWrong)
yield return new ValidationResult("Something went wrong", new[] { "Field2" });

}
}

// the controller action
public HttpResponseMessage Post(RegisterModel model)
{
return Request.CreateResponse(HttpStatusCode.OK);
}

In the controller I expect this error to be retrievable from ModelState["model.Field1"] but instead it is ModelState["model"]. Additionally, because the field name is dropped there can be only one error. If somethingIsWrong && somethingElseIsWrong only one of the errors is available.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>