views:

71

answers:

2

Hi, I have a controller called "Account" in my main site and I would like to reference a method on it from with in an Asp.net MVC 2 Area.

It seems by default that Areas only have access to the controllers within that Area which makes sense, but there doesn't seem to be an option to reference controllers from another area.

Thanks!

+1  A: 

Take a look at this site and see if it helps you out. Basically, in your action links, you need to declare the area you want to reference just like you would an ID or controller.

Controller in default area

html.actionlink("Home", "Index", New with {.area = "", .controller = "Home"})

Controller in another area

html.actionlink("Home", "Index", New with {.area = "someArea", .controller = "Home"})
Tommy
These examples poorly formatted with incorrect syntax. You will get compilation errors using these.
JustinStolle
+2  A: 

Here's a walkthrough: http://msdn.microsoft.com/en-us/library/ee671793.aspx

You pass the area name in the routeValues parameter object.

Url.Action("Index", "Home", new { area = "MyArea" })

The constructor you need to use for Html.ActionLink also has a htmlAttributes parameter, which you can set to null.

Html.ActionLink("Link Text", "Index", "Home", new { area = "MyArea" }, null)

Use an empty string for the default area.

JustinStolle
Also very informative, thanks!
chobo