I'm implementing paging on an ASP.NET MVC view, and I want to call a method in the controller from the view.
Code in the view:
<a href="<%= Url.Action("Search",
new { page = NextPage(Request["exactPage"])).ToString()}) %>">
Controller method:
public string NextPage(string currentPage)
{
return (int.Parse(currentPage) + 1).ToString();
}
How can I call the NextPage method from the view?
thanks!
If you know the number of the current page, could you not just render links where the page value = current page plus/minus 1 for the previous and next links? You don't really need the view to ask the controller what the next/previous page number is. That information can be derived by the view based on the value of the current page index.
EDIT: I suggest that the controller passes an additional value to the view indicating the total number of pages available. The view can then compare this value against the current page number to determine whether to display the next link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With