Possible Duplicate:
How to I find the absolute url of an action in ASP.NET MVC?
Asp MVC Action link absolute url
Hi,
Is there a easy way to generate the full URL for a specific action? I have tried this :
urlHelper.Action("Action", "Controller")
But this does generates a "\".
BestRegards
Edit 1: I have tried this :
urlHelper.Action("List", "Ad", null, "http");
but it only returns : localhost:16055. I was expecting somthing like localhost:16055/Ad/List ?
Use Html.ActionLink("Link Title", "Action", "Controller")
To generate a full link use:
@Html.ActionLink("Link Title", "Action", "Controller", "http", "www.mysampledomain.com",
"_blank", new {id = paramValue}, new { @class="someClass" })
That is the extension overload with all the parameters you can specify. Have a look at this MSDN article http://msdn.microsoft.com/en-us/library/dd492938.aspx
To generate from Controller use this code:
var url = UrlHelper.GenerateUrl(null, "MyAction", "MyController", "http", "www.mydomain.com", String.Empty, null, RouteTable.Routes, this.ControllerContext.RequestContext, false);
url variable will contain a string representation of your URL. You can store it in ViewBag like:
ViewBag.MyUrl = UrlHelper.GenerateUrl(null, "MyAction", "MyController", "http", "www.mydomain.com", String.Empty, null, RouteTable.Routes,
this.ControllerContext.RequestContext, false);
From View call it as:
@ViewBag.MyUrl
That should be it.
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