开发者

w/Url.Action when targeting an Index Page

开发者 https://www.devze.com 2023-02-18 17:24 出处:网络
I\'m running into a situation where a \"fully qualified\" route is not being generated when it needs to be. The following code demonstrates the issue:

I'm running into a situation where a "fully qualified" route is not being generated when it needs to be. The following code demonstrates the issue:

        var junk = Url.Action("Index2", "Reference", new { area = "Admin" });
        junk = Url.Action("Index", "Reference", new { area = "Admin", memberID = 47 });

The first call to Url.Action() produces /Admin/Reference/Index2. The second call produces /Admin/Reference, I guess because "Index" is a default identifier.

Unfortunately, the route mapping (which I haven't modified since it was generated by VS2010) will of course process the second route as being a call for a Reference method on the Admin controller in the root area. There's no way the route resolver can know that the second link is really intended for the Index handler of the Reference controller in the Admin area.

One obvious workaround is to not have开发者_JAVA百科 an Index method in a controller inside an area. But that seems ugly. I'm interested in a better/more robust approach.


Okay, never mind. Turns out the problem was a combination of an incorrect area name and an HttpPost attribute on a method that needs to be able to respond to GET. Please disregard

0

精彩评论

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