开发者

Navigating back to "Home" from an area (MVC2)

I have a few areas in my application that are relatively independent (all navigated to from the master page). So, a开发者_高级运维s of now, I am simply using the "default" MVC2 template (the one you get when you create a new MVC2 project). So the menu looks like this:

HOME AREA1 AREA2 AREA3 AREA4 .... ABOUT

Now, when I first load up the page, I am on the "HOME", and I can click on the ABOUT without issue. I can navigate to any of the areas as well, however, once I navigate to an area page, I cannot get back to my home or about pages (404 not found). When I navigate to them, and click on about, the address bar shows .../AreaX/Home/Home instead of Home/Home as I would expect.

I expect that is has something to do with my routing, but Im not completely sure. I have added/changed nothing with the default routing (which is probably the issue!).

Here is the routing value I have in global.asax(like I said, the default)

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Any thoughts?


When you link, you can set the area to a null (though you need to do it a special way). Something like...

<%: Html.ActionLink("Home", "Home", "Home", new { area = (string)null; }) %>

I may have the number of parameters wrong.

You can link directly like so

<a href="/rooted_path_here">adasda</a>

Or you can write extension methods for the HtmlHelper method that do the same basic thing. I chose this route as I can also authorize users easily. It ends up calling ActionLink.


MVC2 Syntax

<%= Html.ActionLink("Home", "Home", "Home", new { area = (string)null }, null) %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜