开发者

ActionLink/RouteLink based on URL not Controller

I have a controller that uses the following structure:

.com/Object/375

However, I can also use the following URL when I am accessing special admin rights

.com/Admin/Object/375

I use the same user controls whether you're in the Admin section or not, but they both point to the same Controller Object. I need for the links to maintain that URL structure and not try to kick an Admin user back to the Object controller. I am currently using the route name method, where these are my route names (in global.asax):

"Admin/-Object"
"Object/-Object"
"Object-Object"

These route names catch the following routes:

Admin/Object, Admin/Object/555, Object, Object/323

I then use the following in a route link

Html.RouteLink(id, Request.Url.Segments[1] + "-Object", new { id = id })

This works just fine, but has an odd smell - any other ideas?

To clarify: I need the URL to be properly created based on the current URL structure (with or withou开发者_StackOverflow中文版t the Admin) and the routing will point to the correct controller (the same for both URLs) and the admin specific content will be injected into the page only if in the Admin section (based on URL).


Just to wrap this up, using ViewBag is probably a better idea because using the URL segment might result in unexpected errors, especialy if you move the controls or views around.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜