【发布时间】:2014-03-05 21:11:01
【问题描述】:
我认为模型是 IEnumerable。该视图是在创建具有读写操作的新控制器时创建的 mvc 基本视图。 我不希望编辑操作会调用不同的视图,我想在索引视图中添加一个按钮,通过按下特定行中的按钮,该按钮将使用“按下”的模型调用操作结果,并且从那里的逻辑将继续。
观点
@model IEnumerable<V1_ILotto.Areas.Admin.Models.WithdrawalModel>
@{
ViewBag.Title = "בקשות משיכה";
}
<h2>בקשות משיכה</h2>
@using (Html.BeginForm("Approve", "Withdrawals", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.User)
</th>
<th>
@Html.DisplayNameFor(model => model.WithdrawalAmount)
</th>
<th>
@Html.DisplayNameFor(model => model.Balance)
</th>
<th>
@Html.DisplayNameFor(model => model.IsApproved)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.User)
</td>
<td>
@Html.DisplayFor(modelItem => item.WithdrawalAmount)
</td>
<td>
@Html.DisplayFor(modelItem => item.Balance)
</td>
<td>
<p>
<input type="submit" value="Submit" />
</p>
</td>
</tr>
}
</table>
}
控制器
[HttpPost]
public ActionResult Approve(WithdrawalModel withdrawalmodel)
{
if (ModelState.IsValid)
{
//logic for updating the db
return RedirectToAction("Index");
}
return View(withdrawalmodel);
}
注意:视图不是获取单个模型,而是该模型的 IEnumerable
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4