【发布时间】:2017-06-30 12:39:51
【问题描述】:
假设我在所有受限控制器及其相关操作中进行迭代,并将这些控制器和操作添加到我的类中。
public class ControllerActionList
{
public string ControllerName { get; set; }
public string ActionName { get; set; }
}
我以这种方式手动填充以进行模拟:
public List<ControllerActionList> ControllerActionList()
{
List<ControllerActionList> oControllerActionList = new List<ControllerActionList>
{
new ControllerActionList { ControllerName = "Home", ActionName = "Index" },
new ControllerActionList { ControllerName = "Home", ActionName = "DashBoard" },
new ControllerActionList { ControllerName = "Home", ActionName = "Chart" },
new ControllerActionList { ControllerName = "HR", ActionName = "Leave" },
new ControllerActionList { ControllerName = "HR", ActionName = "Loan" },
new ControllerActionList { ControllerName = "HR", ActionName = "NoticeBoard" },
new ControllerActionList { ControllerName = "PayRoll", ActionName = "View" },
new ControllerActionList { ControllerName = "PayRoll", ActionName = "Edit" },
new ControllerActionList { ControllerName = "PayRoll", ActionName = "Process" }
};
return oControllerActionList;
}
现在我应该使用什么逻辑在我的视图中显示这些控制器及其关联的操作名称(见下图)?
请看,控制器名称是 Home、HR 和 Payroll,操作如下所示。
您能否告诉我首先将控制器名称显示为标题并在其操作名称下方显示的最佳方式。就我而言,控制器名称在课堂上重复。
我可以做的一件事是我可以编写一个 for 循环,当控制器名称更改时,我将创建一个新的 div,其中将显示新的或下一个控制器名称。
另外请通过bootstrap给我一些关于如何实现这个设计的提示。
我现在的问题是:
1) 如何在 div 的顶部显示控制器名称及其下方的关联操作,并为每个控制器重复该操作?
2) 如何使用 bootstrap 实现所示设计?
【问题讨论】:
-
在 ControllerName 上使用 GroupBy,然后您可以基于它进行迭代并展平动作名称
-
我不确定如何在控制器名称上使用 group by,因为我需要获取每个控制器的所有操作名称。你能提供一个示例来提示在控制器名称上使用分组吗?
-
Linq GroupBy 有据可查
-
顺便说一句,为了避免混淆,您应该将 ControllerActionList 重命名为 ControllerActionItem 或只是 ControllerAction
-
你能告诉我如何用引导程序实现上述设计吗?如何使用引导程序为每个控制器和操作创建单独的 div?给我一些提示。
标签: bootstrap c# asp.net-mvc twitter-bootstrap