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?
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
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.
Found my issue. I had changed the area name, but failed to update the AreaName property in the Area Registration.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With