Asp.Net MVC: How do I get virtual url for the current controller/view?

前端 未结 5 2007
谎友^
谎友^ 2020-12-24 07:33

Is it possible to get the route/virtual url associated with a controller action or on a view? I saw that Preview 4 added LinkBuilder.BuildUrlFromExpression helper, but it\'

5条回答
  •  Happy的楠姐
    2020-12-24 08:19

    This worked for me:

    <%= this.Url.RouteUrl(this.ViewContext.RouteData.Values) %>

    It returns the current Url as such; /Home/About

    Maybe there is a simpler way to return the actual route string?

提交回复
热议问题