Is there a way to use HTML.RouteLink() to add onto the existing url. For example I have
<%: Html.RouteLink(link.Text, link.Rou开发者_高级运维teValues) %>
My controller is Pages, and my action is somestring. So the generated url would be
localhost/Page/somestring
This is fine. However I would link the generated url when I visit http://localhost:1241/Admin/ section to be
localhost/Admin/Page/somestring
Instead of
localhost/Page/somestring
This localhost/Page/somestring url is setup in my global.asx file to route to view a page, and the localhost/Admin/Page/somestring url is routed to edit the page.
I hope this is making sense and thank you all for your help!
Tyrone
Here Are my two routes which could give you some idea
routes.MapRoute(null,"Pages/{page}", new { controller = "Pages", action = "Page" });
routes.MapRoute("Edit Pages", "Admin/Page/{page}",new { controller = "Admin", action = "EditPage", id =UrlParameter.Optional });
You haven't really given enough information to answer this question thoroughly. As I understand it, you have a partial that uses the same code whether you're in the admin or not to generate the URL. But you want the same code to generate different URLs depending on whether you're in the admin or not.
The trick here is that you need the route values to match the defaults of the route you want to match.
In this case, to link to the non-admin:
Html.RouteLink(linkText, new {controller="Pages", action="Page", page = thePage})
But to link to the admin version
Html.RouteLink(linkText, new {controller="Admin", action="EditPage", page = thePage})
So what you need to do is make sure the partial gets the right values depending on which context it's being used in.
精彩评论