如何在ASP MVC的部分视图中实现选项卡?

时间:2021-07-15 13:23:20

I am not sure where to start to implement tabs in a MVC project. Here is the problem. I want to implement tabs in a partial view but I want the tabs to be available to all my controllers and views. When I am coding the tabs I will need to know the current controller and view so I can modify the Html.ActionLink() with the tab QueryString.

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

How might I go about this

我该怎么做呢

<%= 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;    
<% } %>

1 个解决方案

#1


2  

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

您可以从ViewContext路由值获得当前控制器。

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:

我建议你写一些代码来解决这个问题,你可能想写一个HtmlHelper方法来生成一些HTML -然而:

<%= 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

它应该足够简单,可以从该数据构建上下文感知菜单。

#1


2  

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

您可以从ViewContext路由值获得当前控制器。

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:

我建议你写一些代码来解决这个问题,你可能想写一个HtmlHelper方法来生成一些HTML -然而:

<%= 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

它应该足够简单,可以从该数据构建上下文感知菜单。