c# - 如何在 ASP MVC 的局部 View 中实现选项卡

标签 c# .net asp.net asp.net-mvc partial-views

我不确定从哪里开始在 MVC 项目中实现选项卡。这就是问题所在。我想在局部 View 中实现选项卡,但我希望这些选项卡可用于我的所有 Controller 和 View 。当我编写 tabs 代码时,我需要知道当前的 Controller 和 View ,以便我可以使用 tab 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;    
<% } %>

最佳答案

您可以从 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/

相关文章:

c# - 无论如何修复 ASP.NET gridview 中的列宽

c# - 从c#中的字符串中拆分出字符串

c# - 基类还是普通类?

c# - Visual Studio/MSBuild 将引用类库的 app.config 作为 *.dll.config 复制到当前项目的 bin 文件夹

.net - F#中的Seq.map和Seq.collect之间的区别

.net - UDP、NAT 和设置 "connections"

javascript - ajax POST 调用不同域上的 Web API

c# - 我如何优先考虑 WPF 文本框自动换行?

c# - 统计MVC中Child的记录数

asp.net - 如何在过期之前延长asp.net中的 session 超时