2
ModelBinder에 오류가있어서 ModelState에 오류 코드를 자동으로 추가하고 싶습니다. 내가 kown하는 속성이 ModelBinder를에 오류가있다 수있는 방법,ASP.NET MVC 어떤 속성이 오류인지 찾을 수 있습니까?
//new Attribute
public class TestRequiredAttribute : RequiredAttribute
{
public int ErrorCode { get; set; }
}
하지만 kown하지 않습니다. 그래서 내가 가진처럼 (등 RequiredAttribute, RangeAttribute에 대해) 속성을 추가 할 기본 속성을 확장?
public class TestModelBinder : DefaultModelBinder
{
protected override void SetProperty(ControllerContext controllerContext,
ModelBindingContext bindingContext,
System.ComponentModel.PropertyDescriptor propertyDescriptor,
object value)
{
//the error was happend in here
base.SetProperty(controllerContext, bindingContext, propertyDescriptor, value);
//in here to find which attribute has been error?
to find attribute and to get ErrorCode then
bindingContext.ModelState[modelStateName+code] = ...
}
}
MVC
http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/DefaultModelBinder.cs
의 소스에