开发者

How to reference other Areas?

开发者 https://www.devze.com 2023-01-01 05:13 出处:网络
I have a controller called \"Account\" in 开发者_JS百科my main site and I would like to reference a method on it from with in an Asp.net MVC 2 Area.

I have a controller called "Account" in 开发者_JS百科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!


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.


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"})
0

精彩评论

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

关注公众号