tags:

views:

643

answers:

2

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.

+1  A: 

Edit: for any view/controller combo, not sure you'll find anything simpler than this.

http://&lt;%=Request.Url.Host %><%=Url.Action("action", "controller")%>
John Sheehan
+8  A: 

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.

maz