繁体   English   中英

生成完整的 URL ASP.NET MVC Razor 视图

[英]Generate Full URL ASP.NET MVC Razor Views

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. 有没有办法做到这一点?

你在说:

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

对比

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

Url Model 仅构建链接; Html构建了 HTML。

使用UrlHelper

 Url.RouteUrl( "MyRoute" )

按照 tvanfosson 的建议使用RouteUrl

我只想提一下T4MVC添加了扩展ActionAbsolute以从动作中创建完整的 url。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM