我不确定从哪里开始在 MVC 项目中实现选项卡。这就是问题所在。我想在局部 View 中实现选项卡,但我希望这些选项卡可用于我的所有 Controller 和 View 。当我编写 tabs 代码时,我需要知道当前的 Controller 和 View ,以便我可以使用 tab QueryString 修改 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" })%>
<% } %>
最佳答案
您可以从 ViewContext 路由值中获取当前 Controller 。
我建议您将一些代码放入其中以便解决这个问题,因此您可能需要编写一个 HtmlHelper 方法来在此处生成一些 HTML - 但是:
<%= this.ViewContext.RouteData.Values["controller"] %>
会打印出 Controller 名称
和
<%= this.ViewContext.RouteData.Values["action"] %
Action
根据这些数据构建上下文感知菜单应该足够简单
关于c# - 如何在 ASP MVC 的局部 View 中实现选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2228145/