0
我在我的視圖中有一列表中有一列複選框。我希望用戶能夠根據需要選擇儘可能多的複選框,然後單擊底部的按鈕以禁用它們(此模型中的用戶可以暫停/取消激活並恢復/激活)。我沒有任何錯誤,但是當我點擊按鈕時沒有發生任何錯誤。我附上了我的代碼。謝謝。複選框通過MVC中的ID取消行(視圖/控制器)5
查看
@using (Html.BeginForm("CheckBoxDeactivate"))
{
<table class="table">
<tr>
<th>
Select Users
</th>
<th>
@Html.DisplayNameFor(model => model.ID)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.UserName)
</th>
<th>
@Html.DisplayNameFor(model => model.suspended)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
<input type= "checkbox" name="manageUsers" value="@item.ID" />
</td>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.suspended)
</td>
</tr>
}
</table>
<br />
<input type="button" value="Add Roles" onclick="location.href'@Url.Action("CheckBoxDeactivate", "User")'" />
控制器
[HttpPost]
public ActionResult CheckBoxDeactivate(int[] ids)
{
tbl_Reg_User OAWUser = new tbl_Reg_User();
foreach (var id in ids)
{
OAWUser = db.tbl_Reg_User.Single(o => o.ID == id);
OAWUser.suspended = true;
db.SaveChanges();
}
ViewBag.Message = "Users deactivated successfully!";
return View();
}
它應該是'的onclick = 「location.href =」 @網址.Action(「CheckBoxDeactivate」,「User」)'「'但這是非常醜陋的.jQuery是不是問題?在一個相關的不是,你應該適當e更改爲您的模型,然後將其重新發送到瀏覽器,以便可以將這些更改可視化。 – 2014-10-02 07:17:01
jQuery是不是沒有問題,我正在尋找任何解決方案,讓這個工作。我將如何去通過jQuery來實現這個功能? – JAY3 2014-10-03 00:26:48