3

我不确定从哪里开始在 MVC 项目中实现选项卡。这是问题所在。我想在部分视图中实现选项卡,但我希望这些选项卡对我的所有控制器和视图都可用。当我对选项卡进行编码时,我需要知道当前控制器和视图,以便我可以使用选项卡 QueryString 修改 Html.ActionLink()。

我该怎么办

<%= Html.ActionLink(QuestionSort.SortArray[0], "Current View", "Current Controller", null, new { rel = "nofollow" })%>&nbsp;&nbsp;
<% for (int x = 1; x < QuestionSort.SortArray.Length; x++)
{ %>
    <%= Html.ActionLink(QuestionSort.SortArray[x], "Current View", "Current Controller", new { sort = Server.UrlEncode(QuestionSort.SortArray[x]) }, new { rel = "nofollow" })%>&nbsp;&nbsp;    
<% } %>
4

1 回答 1

2

You can get the current controller from the ViewContext route values.

I would recommend that because you'll be putting some code into this in order to work that out, that you might want to write an HtmlHelper method to generate some of your HTML here - however:

<%= this.ViewContext.RouteData.Values["controller"] %>

Would print out the controller name

and

<%= this.ViewContext.RouteData.Values["action"] %

The action

It should be simple enough to build a context aware menu from this data

于 2010-02-09T14:05:55.020 回答