這裏是我的看法是這樣的:如何在一個表中執行一個簡單的多重選擇ASP.NET MVC4
@model Affiliate
<div class="box paint color_16">
<div class="title">
<h4><i class="icon-tasks"></i><span>@Model.CompanyName's Commissions</span> </h4>
</div>
<div class="content top ">
<div class="subtitle">
@Html.ActionLink("Void", "DeleteInvoice", new { commList = "??", affId = Model.Id }, new { @class = "btn" })
@Html.ActionLink("Create Invoice", "CreateInvoice", new { commList = "??", affId = Model.Id }, new { @class = "btn" })
@Html.ActionLink("Pay", "PayInvoice", new { commList = "??", affId = Model.Id }, new { @class = "btn" })
</div>
<table class="table table-striped table-hover">
<tr>
<h3>Commissions</h3>
</tr>
<tr>
<td></td>
<td>Amount</td>
<td>Status</td>
<td>Action</td>
</tr>
@foreach (var item in Model.Commissions)
{
<tr>
@if (item.Status == ViewBag.PaymentStatus || ViewBag.PaymentStatus == "All")
{
<td>@Html.CheckBox("commId", new { value = item.Id })</td>
<td>@Html.DisplayFor(x => item.PayoutAmount)</td>
<td>@Html.DisplayFor(x => item.Status)</td>
}
</tr>
}
</table>
</div>
我希望能夠做的是,當我打的ActionLink的在頂部,從表中檢查所有檢查的項目,並將該ID列表傳遞給控制器邏輯。我假設一個視圖模型可能是解決方案,這樣的事情:
public Affiliate affilite { get; set; }
public List<int> selectedItems { get; set; }
etc.
但如何讓我選擇的項目到該VM selectedItems容器?
爲什麼你提到視圖模型,仍然在視圖中使用ViewBag?這兩件事情是矛盾的,不應該一起使用。正確的做法當然是使用視圖模型並擺脫ViewBag。所以我將首先爲這個視圖定義一個真實的視圖模型。在這個網站上至少應該有十幾個類似的答案,我已經說明了視圖模型和編輯器模板的用法。 –
這不是最終的代碼,如果你閱讀這個問題,那麼他就不會使用視圖模型。問題是我如何將viewmodel屬性綁定到用戶選擇的任何地方。有用的迴應是受歡迎的,嘲諷和居高臨下的模擬示例代碼中使用的方法屬於另一個論壇。 – ledgeJumper
但是你的視圖模型在哪裏?我只能看到一些'Affiliate'域模型,你已經把它作爲一個屬性放在你稱之爲* view model *的東西中。但這不是視圖模型的工作原理。他們不應該引用您的域模型。應該定義視圖模型以反映您的視圖的要求。 –