当我点击它进入编辑页面时,当我完成编辑并单击更新时,它会重定向回页面,但是编辑的项目不会显示更新。但它应该重定向回到包含更新数据的页面。现在没有回报。这就是我所拥有的:
我已经用控制器编辑了这个问题
if (@Model.items.Count > 0)
{
foreach (var item in @Model.items)
{
<div class="form-group">
@Html.LabelFor(model => model.expense_acccount, htmlAttributes: new { @class = "control-label col-md-2" })
@*@Html.EditorFor(model => model.expense_acccount, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.DropDownListFor(model => model.item.expense_account.index, new SelectList(Model.accountlist, "Value", "Text"), new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.expense_acccount, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.item.price, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextBoxFor(model => model.item.price, new { @id = "price", @class = "form-control", @readonly = "readonly", })
@Html.ValidationMessageFor(model => model.item.price, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.item.quantity, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.item.quantity, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.item.quantity, "", new { @class = "text-danger" })
</div>
@Html.HiddenFor(model => model.item.selecteduomtext)
@Html.HiddenFor(model=>model.item.lineNum)
@Html.HiddenFor(model => model.items)
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" name="Update" class="btn btn-default" />
<input type="button" value="Cancel" name="Cancel" onclick="location.href='@Url.Action("IssueItem","Issue")' " class="btn btn-default" />
</div>
控制器
private Issue getIssue
{
get
{
Issue issue = (Issue)Session["Issue"];
if (issue == null)
{
issue = new Issue();
Session["Issue"] = issue;
}
return issue;
}
}
public ActionResult Edit(int id)
{
getIssue.item = getIssue.items[id - 1];//Returns the requested item for editing
return View(getIssue);
}
/// <summary>
/// Gets the changes submitted from the user and updates the Item in the List
/// </summary>
/// <param name="issue"></param>
/// <returns></returns>
[HttpPost]
public ActionResult Edit(Issue issue)
{
int indx = issue.item.lineNum - 1;
getIssue.items[indx] = issue.item;
return RedirectToAction("IssueItem");
}