C# 4.0 如何将值设置为ValueProvider+MVC 4的AttemptedValue
我陷入了一个奇怪的问题 我的MVC视图中有一个复选框,它是从jQuery中呈现的C# 4.0 如何将值设置为ValueProvider+MVC 4的AttemptedValue,c#-4.0,asp.net-mvc-4,C# 4.0,Asp.net Mvc 4,我陷入了一个奇怪的问题 我的MVC视图中有一个复选框,它是从jQuery中呈现的 <div> <label for="check" class="chk"> Del ? <input id="IsSoftDeleted" name="IsSoftDeleted" data-val-required="The Del? field is required." data-val="true" type="checkbox" class="
<div>
<label for="check" class="chk">
Del ?
<input id="IsSoftDeleted" name="IsSoftDeleted" data-val-required="The Del? field is required." data-val="true" type="checkbox" class="check" />
</label>
</div>
这很好,组织的IsSoftDeleted属性现在为true或false
但是,由于在我的模型类中删除了ISSOFTIN布尔值,因此ModelState引用的是尝试值,即on,ModelState变为false
我已尝试将值设置为AttemptedValue属性,但无法访问
有人能告诉我如何修复它吗?冷静点!!!
我们目前在jQuery中处理它
我想我们不能扩展valueprovider类,如果是,请给出一些方法,我们如何做到
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
bool softDelete = Convert.ToBoolean(bindingContext.ValueProvider.GetValue("IsSoftDeleted").AttemptedValue != null
&& bindingContext.ValueProvider.GetValue("IsSoftDeleted").AttemptedValue == "on" ? "true" : "false");
return OrgFactory.Create(bindingContext.ValueProvider.GetValue("Caption").AttemptedValue,
bindingContext.ValueProvider.GetValue("NameInUse").AttemptedValue,
bindingContext.ValueProvider.GetValue("Description").AttemptedValue,
softDelete, new Party());
}