使用PagedList.mvc时如何在同一页面上保留/保留 [英] How to remain/retain on the same page when using PagedList.mvc
本文介绍了使用PagedList.mvc时如何在同一页面上保留/保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PagedList.Mvc,并且添加了一种很好的方式来浏览mvc Web应用程序中的各个页面.但是,当我单击编辑"或详细信息"选项卡并保存更改时,我将被发送回第一页.我想保留在进行更改的同一页面上.
I am using PagedList.Mvc and I have added a nice way to navigate across various pages in a mvc web application. However, when I click on an "edit" or "details" tab and save changes I am sent back to the 1st page. I want to remain on the same page where the changes were made.
这是控制器中的代码:
// GET: Item
public ActionResult Index(int? page)
{
var items = db.Items.Include(i => i.PurchaseOrder);
return View(items.ToList().ToPagedList(page ?? 1, 3));
}
这是视图中的代码:
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<PurchaseOrders.Models.Item>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().ItemDescription)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Quantity)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Price)
</th>
<th>
@Html.DisplayNameFor(model => model.First().DueDate)
</th>
<th>
@Html.DisplayNameFor(model => model.First().DateReceived)
</th>
<th>
@Html.DisplayNameFor(model => model.First().Comments)
</th>
<th>
@Html.DisplayNameFor(model => model.First().PurchaseOrder.PurchaseRequest_)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ItemDescription)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.DisplayFor(modelItem => item.DueDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateReceived)
</td>
<td>
@Html.DisplayFor(modelItem => item.Comments)
</td>
<td>
@Html.DisplayFor(modelItem => item.PurchaseOrder.PurchaseRequest_)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ItemId }) |
@Html.ActionLink("Details", "Details", new { id=item.ItemId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ItemId })
</td>
</tr>
}
</table>
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
请帮助!
推荐答案
例如,您可以将附加的"page"参数传递给您的编辑方法
You could pass an additional 'page` parameter to your edit method, for example
在您的索引方法中,添加
In your Index method, add
ViewBag.CurrentPage = page; // or use a view model property
那么您的链接将是
@Html.ActionLink("Edit", "Edit", new { id=item.ItemId, page = ViewBag.CurrentPage})
然后使用您的编辑方法
[HttpGet]
public ActionResult Edit(int ID, int page)
{
ViewBag.CurrentPage = page; // pass current page to edit view
以及您的修改视图
@using (Html.BeginForm(new { page = ViewBag.CurrentPage })) {
然后在您发布方法
[HttpGet]
public ActionResult Edit(EditModel model, int page)
{
.... // Save
return RedirectToAction("Index", new { page = page });
这篇关于使用PagedList.mvc时如何在同一页面上保留/保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文