2016-11-16 145 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});