Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.Action() with area returns empty string

Tags:

asp.net-mvc

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?

like image 433
teh4x Avatar asked Feb 15 '13 15:02

teh4x


People also ask

What is the difference between URL action () and HTML action ()?

Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

What does URL action do?

A URL action is a hyperlink that points to a web page, file, or other web-based resource outside of Tableau. You can use URL actions to create an email or link to additional information about your data. To customize links based on your data, you can automatically enter field values as parameters in URLs.


2 Answers

Found my issue. I had changed the area name, but failed to update the AreaName property in the Area Registration.

like image 178
teh4x Avatar answered Sep 18 '22 08:09

teh4x


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

like image 23
Rajmond Burgaj Avatar answered Sep 22 '22 08:09

Rajmond Burgaj