使用Html.ActionLink(“链接名称”,“行动”,“控制器”)
要生成一个完整的链路中使用:
@Html.ActionLink("Link Title", "Action", "Controller", "http", "www.mysampledomain.com",
"_blank", new {id = paramValue}, new { @class="someClass" })
这是所有参数的扩展超载你可以指定。看看这个MSDN文章http://msdn.microsoft.com/en-us/library/dd492938.aspx
在从控制器生成使用此代码:
var url = UrlHelper.GenerateUrl(null, "MyAction", "MyController", "http", "www.mydomain.com", String.Empty, null, RouteTable.Routes, this.ControllerContext.RequestContext, false);
url变量将包含URL的字符串表示。您可以在ViewBag其存储这样的:
ViewBag.MyUrl = UrlHelper.GenerateUrl(null, "MyAction", "MyController", "http", "www.mydomain.com", String.Empty, null, RouteTable.Routes,
this.ControllerContext.RequestContext, false);
从视图中称其为:
@ViewBag.MyUrl
这应该是它。
这是在一个视图,或在控制器代码的上下文? – Tejs 2012-04-24 15:23:42
只需预先安装主机/协议信息? – 2012-04-24 15:23:54