1
我有一個自定義模型綁定器,我檢查字符串屬性是否爲null並將其替換爲空字符串。如何將asp.net mvc 3自定義模型綁定器GetPropertyValue屬性綁定器參數
我重寫BindProperty方法,但不知道如何從PropertyDescriptor的
GetPropertyValue(controllerContext, bindingContext, propertyDescriptor,
<What should I pass for the IModelBinder?>);
這裏獲得屬性值是BindProperty代碼
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor.PropertyType == typeof(string))
{
object s = GetPropertyValue(controllerContext, bindingContext, propertyDescriptor, null);
if (s == null)
{
SetProperty(controllerContext, bindingContext, propertyDescriptor, "");
}
}
}
你有沒有找到解決辦法? – 2017-10-04 08:47:42