可以说我有 3 个菜单项。每个内部都有(例如)5个链接。所以我有这样的事情:
//This is just some test-code. normally i''ll get the data from a database
List<NavigationModel> navigation = new List<NavigationModel>();
Random randomInt = new Random();
for (int i = 0; i < 5; i++)
{
NavigationModel m = new NavigationModel();
m.MenuName = "Users";
m.LinkName = "Link (" + i + ")";
m.ControllerName = "AAA";
m.ActionName = "Function" + i;
m.SortingMenu = 5;
navigation.Add(m);
}
for (int i = 0; i < 5; i++)
{
NavigationModel m = new NavigationModel();
m.MenuName = "Help";
m.LinkName = "Link (" + i + ")";
m.ControllerName = "BBB";
m.ActionName = "Function" + i;
m.SortingMenu = 10;
navigation.Add(m);
}
for (int i = 0; i < 5; i++)
{
NavigationModel m = new NavigationModel();
m.MenuName = "Home";
m.LinkName = "Link (" + i + ")";
m.ControllerName = "CCC";
m.ActionName = "Function" + i;
m.SortingMenu = 2;
navigation.Add(m);
}
navigation = navigation.OrderBy(x => x.SortingMenu).ToList();
如您所见,我将获得 3 个正确排序的菜单项,但我需要从 0 开始排序,然后是 1,2 ...
如何在没有硬编码或数据库更新命令的情况下做到这一点?