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

Edited Issue: ValidationResult returned from CustomValidation method with memberName specified isn't associated with corresponding field [1534]

$
0
0
Porting from https://aspnet.codeplex.com/workitem/7765:

I found that if you implement a validation check like below, the error message is printed with @Html.ValidationSummary(true), but, not with the @Html.ValidationMessageFor(model => model.Name) for the field. Note, the field name is being specified in the ValidationResult constructor. This behavior is different than if you were to use IValidatableObject and implement the validation that way. In that case, the error message prints with @Html.ValidationMessageFor(model => model.Name) and not in the summary like it's supposed to. The behavior should be the same for both. Also, it seems like custom validation methods specified using CustomValidationAttribute should be allowed to return an IEnumerable<ValidationResult> in addition to a single result. The documentation for that page could use improvement also.

[CustomValidation(typeof(Person), "ValidateName")]
public class Person
{
public string Name { get; set; }

public static ValidationResult ValidateName(Person person, ValidationContext validationContext)
{
return new ValidationResult("Value is invalid", new[] { "Name" });
}
}

daroth: Same behavior in MVC 5

Viewing all articles
Browse latest Browse all 7215

Trending Articles