Reputation: 491
I'm using Razor in MVC 4. I'm trying to make a URL from a view in an area to a controller action in another area. The following returns an empty string:
@Url.Action("Action", "MyController", new { area = "OtherArea" })
I've done some testing with other options, and the following returns a URL, but it's wrong:
@Url.Action("Action", "MyController", new { parameter = 1 })
The resulting URL is /App/IncorrectArea/My/Action?parameter=1. Note the incorrect area; Url.Action is assuming (since I didn't pass an area) that the controller lives in the current area which it does not!
Any ideas?
Upvotes: 16
Views: 17424
Reputation: 4002
I had the same problem because I changed the RegisterRoutes
method from {controller}/{action}/{id}
to {action}/{id}
just to emit controller name from URL
Upvotes: 2
Reputation: 491
Found my issue. I had changed the area name, but failed to update the AreaName property in the Area Registration.
Upvotes: 12