如何在 ASP MVC 中的部分视图中实现选项卡
我不知道从哪里开始在 MVC 项目中实现选项卡。问题就在这里。我想在部分视图中实现选项卡,但我希望选项卡可供所有控制器和视图使用。当我对选项卡进行编码时,我需要知道当前的控制器和视图,以便我可以使用选项卡查询字符串修改 Html.ActionLink()。
我该怎么办?
<%= Html.ActionLink(QuestionSort.SortArray[0], "Current View", "Current Controller", null, new { rel = "nofollow" })%>
<% 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" })%>
<% } %>
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.
How might I go about this
<%= Html.ActionLink(QuestionSort.SortArray[0], "Current View", "Current Controller", null, new { rel = "nofollow" })%>
<% 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" })%>
<% } %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从 ViewContext 路由值获取当前控制器。
因为您将在其中放入一些代码来解决这个问题,所以您可能想要编写一个 HtmlHelper 方法来生成一些 HTML 在这里 - 但是:
会打印出控制器名称
和
操作
我建议, 应该足够简单,可以根据这些数据构建上下文感知菜单
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:
Would print out the controller name
and
The action
It should be simple enough to build a context aware menu from this data