سلام
چطور می تونم از PagedList داخل یک اکشن(ویو اون) که دارای اتریبیوت httppost هست استفاده کنم
هرچی تلاش کردم به طور مستقیم نمی شد فکر کنم با پارشیال ویو باید این کار رو کرد ولی نمی دونم چطوری.
ممنون می شم راهنمایی بفرمایید
مثلا
این کنترلرم هست
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WebApp.Models; using PagedList; namespace WebApp.Controllers { public class HomeController : Controller { // GET: Home public ActionResult Index() { return View(); } [HttpPost] public ActionResult posted(View_model entry, int? page) { AdventureWorks2012Entities db = new AdventureWorks2012Entities(); List<WebApp.Models.Person> model = db.People.Where(p => p.BusinessEntityID < entry.ProductId).ToList(); int pagenumber = (page ?? 1); int pagesize = 10; return View(model.ToPagedList(pagenumber, pagesize)); } } }
این ویو ایندکس هست
@model WebApp.Models.View_model @{ ViewBag.Title = "Index"; } <h2>Index</h2> @using (Html.BeginForm("posted","Home",FormMethod.Post)) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Person</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.ProductId, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.ProductId, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.ProductId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> <script src="~/Scripts/jquery-1.10.2.min.js"></script> <script src="~/Scripts/jquery.validate.min.js"></script> <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
اینم ویو پستد هست
IPagedList<WebApp.Models.Person> @using PagedList.Mvc @using PagedList @{ ViewBag.Title = "posted"; } <h2>posted</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.First().BusinessEntityID) </th> <th> @Html.DisplayNameFor(model => model.First().PersonType) </th> <th> @Html.DisplayNameFor(model => model.First().NameStyle) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.BusinessEntityID) </td> <td> @Html.DisplayFor(modelItem => item.PersonType) </td> <td> @Html.DisplayFor(modelItem => item.NameStyle) </td> <td> @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) </td> </tr> } </table> @Html.PagedListPager(Model,page=>Url.Action("index",new { page}))
منظورتون صفحه بندی است ؟
کافیست بعد از ثبت در اکشن Post شما Return Redirect کنید به آدرس مورد نظر و شماره صفحه را نیز در Url قرار دهید
مرسی ولی چطور مدل رو به اون اکشن بدم با route value نمی شه؟ چه کنم؟
بعنوان ورودی متد شماره صفحه را نیز دریافت کنید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)