使用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