I'm new to ASP.NET MVC and I'm trying to get the full url to a action when working in a view. I need this to submit to a third party API as a callback. For example what I need is
http://myserver.com/controller/action
When I use
<%= Url.Action("action", "controller") %>
I get
/controller/action
I know several ways to add the server base-path to this but I'm wondering what is the preferred way to do this in the ASP.NET MVC view?
EDIT: Just to clarify, it's not the URL for the current view/action it's for another action in the same controller.
In order to catch variations in the protocol (http / https), diffrent ports and virtual paths (can't always assume we will be in server root) I ended up with the following solution:
<%= Request.Url.GetLeftPart(System.UriPartial.Authority) + Url.Action("action", "controller")%>
I'm working on moving this to a extension method to make it prettier.
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