简体   繁体   中英

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 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.

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
) %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM