Generate Full URL ASP.NET MVC Razor Views

血红的双手。 提交于 2021-02-04 16:50:34

问题


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?


回答1:


Use the UrlHelper.

 Url.RouteUrl( "MyRoute" )



回答2:


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.




回答3:


Use RouteUrl as tvanfosson proposes.

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



来源:https://stackoverflow.com/questions/6306388/generate-full-url-asp-net-mvc-razor-views

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!