将所选复选框值从视图传递给控制器

时间:2013-03-14 04:33:28

标签: asp.net-mvc

我有这样的观点:

@model SCWW.Areas.OnlineBookings.Models.Updates.UpdateDetailsModel

@using (Html.BeginForm("Apply", "Updates", new { area = "OnlineBookings", consignmentKey = Model.ConsignmentKey }, FormMethod.Post, new { id = "updateableForm" }))
{
<fieldset>
    <legend>Updateable - @Html.DisplayFor(model => model.ConsignmentKey)</legend>
    <div class="well well-small ">
        @Html.HiddenFor(m => m.ConsignmentKey)

        <table id="updateDetails" class="table table-bordered table-striped table-hover dataTable">
            <tbody>
                <tr>
                    <td>Completed Date</td>
                    <td>@Html.CheckBoxFor(m => m.Apply)</td>
                    <td class="table-input">@Html.TextBoxFor(m => m.CompletedDate, new { Disabled = "Disabled" })</td>
                </tr>
                <tr>
                    <td>Cancelled Date</td>
                    <td>@Html.CheckBoxFor(m => m.Apply)</td>
                    <td class="table-input">@Html.TextBoxFor(m => m.CancelDate, new { Disabled = "Disabled" })</td>
                </tr>
                <tr>
                    <td>Booking Number</td>
                    <td>@Html.CheckBoxFor(m => m.Apply)</td>
                    <td class="table-input">@Html.TextBoxFor(m => m.BookingNumber, new { Disabled = "Disabled" })</td>
                </tr>

            </tbody>
        </table>
        <button type="submit" id="applyProxy" name="action" value="@FormAction.Apply" class="btn btn-success">Update</button>
    </div>

</fieldset>

}

控制器:

 [HttpPost]
    public ActionResult Apply(UpdateDetailsModel model, FormAction action)
    {
        if (!ModelState.IsValid)
        {
            return View("Submit",     GenerateViewModel(model.ConsignmentKey));
        }

        updateableService.Update(model.ConsignmentKey,"CompletedDate", model.ToDto());

        return RedirectToActionWithHash("Details", "otherActionsTab", "Bookings",
                                       new { consignmentKey = model.ConsignmentKey });
    }

在我看来,每行有3行,每行有一个复选框。单击“视图”上的“更新”按钮时,仅选中一个复选框。 我怎么知道选中了哪个复选框?如何将所选复选框值从视图传递给控制器​​ - 在控制器中应用(UpdateDetailsModel模型,FormAction操作)

1 个答案:

答案 0 :(得分:1)

您使用相同的型号属性3次。您需要为每个条件创建单独的属性。