我的模型活页夹中有以下方法:
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
if (bindingContext.ValueProvider.GetValue("Id") == null)
{
string s = bindingContext.ValueProvider.GetValue("IsSoftDeleted").AttemptedValue;
bool d = Convert.ToBoolean(s);
return OrgFactory.Create(bindingContext.ValueProvider.GetValue("Caption").AttemptedValue,
bindingContext.ValueProvider.GetValue("NameInUse").AttemptedValue,
bindingContext.ValueProvider.GetValue("Description").AttemptedValue,
d, new Party());
}
else
{
return OrgFactory.Create(bindingContext.ValueProvider.GetValue("Caption").AttemptedValue,
bindingContext.ValueProvider.GetValue("NameInUse").AttemptedValue,
bindingContext.ValueProvider.GetValue("Description").AttemptedValue,
Convert.ToBoolean(bindingContext.ValueProvider.GetValue("IsSoftDeleted").AttemptedValue));
}
}
在 create.cshtml 视图中,如果我检查 IsSoftDeleted 的复选框,它在模型活页夹中的值为“真,假”,而它应该只为真。
你能告诉我我做错了什么吗?
创建.cshtml
@using PartyBiz.Models.Objects
@model Organization
@using (Html.BeginForm("Create", "Organization", FormMethod.Post))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Create a New Organization</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Caption)
@Html.EditorFor(model => model.Caption, new { @class = "txt"})
@Html.ValidationMessageFor(model => model.Caption)
</div> <br />
<div class="editor-label">
@Html.LabelFor(model => model.NameInUse)
@Html.EditorFor(model => model.NameInUse, new { @class = "txt"})
@Html.ValidationMessageFor(model => model.NameInUse)
</div> <br />
<div class="editor-label">
@Html.LabelFor(model => model.Description)
@Html.EditorFor(model => model.Description, new { @class = "txt"})
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(O => O.IsSoftDeleted)
@Html.EditorFor(O => O.IsSoftDeleted)
@Html.ValidationMessageFor(O => O.IsSoftDeleted)
</div>
<br />
<input type="submit" value="Create" />
</fieldset>
}