我是模特bindingcontext
的新手,无法理解为什么我会继续null
获得结果
据我了解,我需要实现IUnvalidatedValueProvider
以关闭验证(因为用户发布了html)。
public class AccountFormBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
//Cast the value provider to an IUnvalidatedValueProvider, which allows to skip validation
IUnvalidatedValueProvider provider = bindingContext.ValueProvider as IUnvalidatedValueProvider;
var result = provider.GetValue(bindingContext.ModelName,true);
return result.AttemptedValue;
}
}
答案 0 :(得分:0)
那么,您只是想允许发布HTML?您不需要自定义模型绑定器。只需将[AllowHtml]
添加到应允许包含帖子值的HTML的任何属性中:
public class MyViewModel
{
...
[AllowHtml]
[DataType(DataType.Html)]
public string Content { get; set; }
...
}
答案 1 :(得分:0)
我最后这样做了
HttpRequestBase request = controllerContext.HttpContext.Request;
var re = request.Unvalidated("CMessage");