Something among the lines should do the job:
public class BBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (value != null)
{
if (value.AttemptedValue == "1")
{
return true;
}
else if (value.AttemptedValue == "0")
{
return false;
}
}
return base.BindModel(controllerContext, bindingContext);
}
}
and register in Application_Start
:
ModelBinders.Binders.Add(typeof(bool), new BBinder());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…