MVC 3 Routing to an Area
How does one Route from one Area开发者_如何学C to another?
In the default project, there are no area's, but once you add an Area, how could I redirect from the default Home page to a page inside my new Area?
I don't see a RedirectTo* method which takes a parameter for an Area name anywhere. Unless I'm missing the point of Area's completely?
Inside our views, we don’t need to specify the area route data value when generating links to other controller actions inside that area. We only supply the action name, because the controller and area name will come from the existing route data for the current request. If we want to link to an outside area, we’ll need to supply that route data explicitly.
return RedirectToAction("yourAction", "YourController", new { area = "yourArea" });
The "area" route value needs to match the AreaName used in the AreaRegistration class for the URL to generate correctly.
This code in your view will link you to the Admin area, regardless of which area you are currently in:
@Html.ActionLink("Click Me", "ActionName","ControllerName",new { Area = "AreaName"}, null )
e.g. (poor made up example)
@Html.ActionLink("Administer User", "Home","UserAdmin",new { Area = "Admin"}, null )
The final null in the call corresponds to HtmlAttributes
, and I usually leave it as null.
精彩评论