Just a short message to let you know that the MVC Pager demo is upgraded to ASP.NET MVC3 and VS 2010. Get it at https://github.com/martijnboland/MvcPaging.
MVC Pager update
Just a short message to let you know that the MVC Pager demo is upgraded to ASP.NET MVC3 and VS 2010. Get it at https://github.com/martijnboland/MvcPaging.
Pingback:Tweets die vermelden Martijn Boland » MVC Pager update -- Topsy.com
Dear Martijn,
thank you so much for your mvcpager. It was very important for my website development. I would like to ask you what I have to do if instead of categoryName using string I need to call categoryId from db.categories?. I cannot move forward with that receiving error “this dictionary requires a model item of type IPagedList`1[Social.ViewModels.ProductViewModelList]”
thank you so much for your time.
@sebastian: in your situation I’d create a view model for the page that has a SelectList of categories in it and a also an IPagedList with the results. The categories are displayed as
<%= Html.DropDownList("CategoryId", Model.Categories) %>
and the pager would be something like
<%= Html.Pager(Model.Results.PageSize, Model.Results.PageNumber, Model.Results.TotalItemCount, new { CategoryId = Model.Categories.SelectedValue } )%>
Hi Martijn, thank you so much for your prompt response. I created the following controller taking into consideration your example
public ActionResult Browse(int categoryId, int? page)
{
const int defaultPageSize = 20;
IList allProducts = new List();
categoryName = ?
int currentPageIndex = page.HasValue ? page.Value – 1 : 0;
var products = allProducts.Where(p => p.CategoryId.Equals(categoryId)).ToPagedList(currentPageIndex, defaultPageSize);
ViewData[“CategoryDisplayName”] = categoryId;
return View(products);
}
but on categorydisplayname you took the value from categoryname which is a string or ?? this.categories . In the case that you need to change that value for a category model, retrieving and integer what do you suggest to do?. sorry if its a newbie question but I´m learning with your example.
thank you so much,brgds
Hi Martijn, I´ve been trying but I cannot move forward in my implementation of the pager. I´m only trying to display a list of products (from db.product) filtered by categoryid (from db.category). if categoryid=2 display those products paginated. I tried to use the example with string details but with no success. I dont know what i have to do in order to use the mvc pager sucessfully. Thanks in advance for any help.
brgds.
@sebastian: could you please try the solution that I proposed earlier?
You need to create a class (ViewModel) that contains both the list of categories (as SelectList) and the results as IPagedList.
You might also add the selected categoryId as property of the view model if the SelectedValue doesn’t work. Hopefully this will help you a little.
ok, I will do that. thank you!