开发者

Generate Full URL ASP.NET MVC Razor Views

开发者 https://www.devze.com 2023-03-12 04:30 出处:网络
I am trying to generate the full URL for a route link in my razor view for ASP.NET MVC 3.I know I can use Html.RouteLink to generate a link however all I want is the URL, not the surrounding a tag wra

I am trying to generate the full URL for a route link in my razor view for ASP.NET MVC 3. I know I can use Html.RouteLink to generate a link however all I want is the URL, not the surrounding a tag wrapper. Is there开发者_运维知识库 a way to do this?


Are you talking about:

<a href="@Url.Action("Action", "Controller", new { @id = "2" })">
    Link to Page</a>

vs.

@Html.ActionLink("Link to page", "Action", "Controller", new { @id = "2" })

The Url Model builds only Links; Html builds the HTML as well.


Use the UrlHelper.

 Url.RouteUrl( "MyRoute" )


Use RouteUrl as tvanfosson proposes.

I would just want to mention T4MVC adds the extension ActionAbsolute to create a full url from an action.

0

精彩评论

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