2017-04-08 45 views
0

withing ViewBag我使用的是ViewBag在我看來是這樣的:使用URL(鏈接)在ASP.NET MVC C#

ViewBag.Text = "This is the" + @Html.ActionLink("link","action","Home"); 

,它不工作。有什麼辦法可以做到嗎?謝謝。

+0

什麼不工作?你期望的行爲是什麼? – Shyju

+0

我想有一個工作的網址,但相反,它顯示爲文本。 –

回答

3

您應該使用Html.Raw方法。

@{ 
    ViewBag.Text = "This is the" + @Html.ActionLink("link", "Index", "Home"); 
} 

@Html.Raw(ViewBag.Text) 

如果單純使用@ViewBag.Text,剃刀將呈現類似

This is the<a href="/home/index">link</a> 

因爲當它與@

Html.Raw方法前綴將返回標記,而不剃刀將HTML編碼表達的結果Html編碼。

+0

謝謝你的回答! –