0
我有這樣一個觀點:傳遞所選擇的複選框值至控制器
@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點各自的行與一個複選框。當我點擊View上的「更新」按鈕時,只有一個複選框被選中。 我將如何知道選中了哪個複選框?如何將選定的複選框值從視圖傳遞給控制器 - 在控制器中應用(UpdateDetailsModel模型,FormAction動作)
是否有其他方式,而不是使用3個獨立的屬性?請。 – user1282609 2013-03-14 05:20:22
沒有什麼不明確的。您可以根據哪個文本框在其中輸入內容進行猜測,但只要用戶將輸入放入> 1文本框中即使它們僅選擇一個選項,也會中斷。你需要3個屬性3個選擇。 – Kevin 2013-03-14 17:48:54