Creating links to current controller in a Partial view
I have a partial view that renders a paging control that is reused across several views and actions. But I can't work out how to generate a URL for my current action just appending a page number without knowing the action and controller I came from in the partial view.
Can 开发者_开发百科you get this information in a partial view?
You could fetch the current controller and action from the route data:
<%= Html.ActionLink(
"link text",
ViewContext.RouteData.GetRequiredString("action"),
ViewContext.RouteData.GetRequiredString("controller"),
new { page = "123" },
null
) %>
You would need to pass that information into the into the ViewData
for the paging control. Look at the overloads for RenderPartial
to pass additional view data.
精彩评论