20 lines
673 B
C#
20 lines
673 B
C#
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
|
{
|
|
public class RequiredAttributeAdapter : DataAnnotationsModelValidator<RequiredAttribute>
|
|
{
|
|
public RequiredAttributeAdapter(RequiredAttribute attribute)
|
|
: base(attribute)
|
|
{
|
|
}
|
|
|
|
public override IEnumerable<ModelClientValidationRule> GetClientValidationRules(
|
|
[NotNull] ClientModelValidationContext context)
|
|
{
|
|
var errorMessage = GetErrorMessage(context.ModelMetadata);
|
|
return new[] { new ModelClientValidationRequiredRule(errorMessage) };
|
|
}
|
|
}
|
|
} |