2016-11-16 158 views
1

林建設動態菜單在我的MVC的項目,所以在我的控制器我有以下幾點:ASPNET MVC渲染服務器端@ Html.ActionLink

// list accounts 
       menu.Add(new Model.Custom.Menu() { Active = true, Url = "dashboard.html", Icon = "mdi mdi-account-card-details", Items = null, Text = "List Accounts" }); 

眼下dashboard.html鏈接是硬編碼的,但要@Html.ActionLink,所以我需要它呈現正確的道路。

任何線索?

+2

'Url = Url.Action(...) – haim770

回答

0

您可以使用UrlHelper來調用Action方法,該方法將返回操作方法的正確相對路徑。

var url=new UrlHelper(Request.RequestContext); 
var newUrl = url.Action("Dashboard"); 
//The above will generate the path to Dashboard action method. 

menu.Add(new Model.Custom.Menu() { Active = true, Url = newUrl});