1

基本上就是标题所说的:

这必须在没有提交按钮的情况下发生。这就是我得到的,但不知道如何更进一步:

看法

<% using (Html.BeginForm("UpdateReleaseState", "Articles", new{reference=Model.Reference, CheckboxState=true})) {%>
                    <%=Html.CheckBox("CheckboxState", Model.DoNotCheckReleaseState)%> Do not check release state
</div>

行动

 [HttpPost]
 public ActionResult UpdateReleaseState(Guid reference, bool CheckboxState)
 {
     throw new NotImplemtedException();
 }

在我看来,我正在尝试传递复选框的值,但不知道要提供什么作为参数。目前它是 check=true

4

2 回答 2

1

在您的CheckBox方法中,您已经指定了它的名称 - CheckboxState。因此,表单发布后,请求将包含部分CheckboxState=trueCheckboxState=false。现在您需要做的就是为操作参数指定相同的名称(不区分大小写):

public ActionResult UpdateReleaseState(Guid reference, bool checkboxState)
于 2013-06-13T14:08:26.203 回答
0

您需要将签名更改为:

public ActionResult UpdateReleaseState(Guid reference, bool CheckboxState)

MVC 使用名称来绑定值。还有一点需要注意,大小写很重要,因为它更易于解释。但正如 Andrei 所发现的,它与它的工作无关。

于 2013-06-13T14:08:25.983 回答