Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlHelper.GenerateUrl

Can you provide a sample of using Urlhelper.GenerateUrl within an Action Filter using only the target controller and action ?

like image 685
plippard Avatar asked Mar 28 '11 01:03

plippard


2 Answers

var url = UrlHelper.GenerateUrl(null, "action", "controller", null, RouteTable.Routes, HttpContext.Current.Request.RequestContext, false);

or

var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);    
var url = urlHelper.Action("action", "controller");
like image 155
Timeless Avatar answered Nov 10 '22 02:11

Timeless


You can use Url.Action( Action , Controller ).

Here an example to be more clear.

<ul>

    <li><a href="@Url.Action("Details" , "Reports", new { Id = report.Id })">
        <img src="~/Content/icons/view.svg" /></a></li>

    <li><a href="@Url.Action("Edit" , "Reports", new { Id = report.Id })">
        <img src="~/Content/icons/edit.svg" /></a></li>

    <li><a href="@Url.Action("Delete" , "Reports", new { Id = report.Id })">
        <img src="~/Content/icons/remove.svg" /></a></li>

</ul>
like image 27
Moises Ribeiro Avatar answered Nov 10 '22 02:11

Moises Ribeiro