开发者

UrlHelper.GenerateUrl

开发者 https://www.devze.com 2023-02-19 23:10 出处:网络
Can you provide a sample of using Urlhelper.GenerateUrl within an Action Filter using only the target con开发者_JS百科troller and action ?var url = UrlHelper.GenerateUrl(null, \"action\", \"controller

Can you provide a sample of using Urlhelper.GenerateUrl within an Action Filter using only the target con开发者_JS百科troller and action ?


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");


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消