I had a doubt which is the following:
When I use the following code:
@(Html.ActionLink("Click Me", "ACTION", new {QueryName = ViewBag.QueryName}))
I will get an HTML output like this:
<a href=”http://localhost/ControllerName/ACTION?QueryName=098″> Click Me </a>
Ok, but what if I want to have the following as an HTML output?
<span > I want just the “href” part of the action link http://localhost/ControllerName/ACTION?QueryName=098 , without the “a” tag </span>
Do I have to write an extension for it or do I have some preexistent provision to do it?
I hope I was clear enough.
Thanks
UPDATE
So far I wrote an extension, which is clearly not the best way to do it, as you can see below, but I needed it:
public static class ActionURLPathExtension
{
public static MvcHtmlString ActionURLPath(this HtmlHelper helper , string ActionName, string ControllerName, object RouteValues)
{
string resultURL=LinkExtensions.ActionLink(helper," ",ActionName,ControllerName, RouteValues, new object()).ToHtmlString();
resultURL= resultURL.Replace("</a>","") .Replace("<a href=\"","") .Replace("\">","").Trim() ;
return MvcHtmlString.Create(helper.ViewContext.HttpContext.Server.UrlDecode(resultURL));
}
}
In the HTML I used it like this:
<span>Now you can paste this URL in your address bar : @(Html.ActionURLPath("CarregarFiltros", "Filtros", new { QueryId = "%0" , noCache = new Random().Next(0,1989) }))</span>
You can use
Url.Action, like so:or if you need the fully qualified URL: