仅显示一定数量的数组元素 [英] Display only a certain number of array elements
问题描述
你好。
我在razor mvc的asp.net工作。
我试图给一个html标签的类名,存储类名在数组中作为字符串。
我用foreach循环遍历数组,我确实工作,我得到了类,但问题是我的数组中有5个元素,我只需要尽可能多的类名我有的标签。
下面我会告诉你我的意思。
数字{0}和{1}是其他的东西。
Hello.
I am working in asp.net in razor mvc.
I am trying to give a class name to an html tag, the class name is stored in an array as a string.
I am looping through the array with a foreach and i does work, i get the class, but the problem is that i have 5 elements in my array and i only need as many class names as many html tags i have.
Below i will show you what i mean.
The number {0} and {1} are for something else.
string[] liclasses = { "fc-orange", "fc-sky", "fc-red", "fc-green", "fc-per" };
foreach (string lic in liclasses)
{
html += string.Format("<li class=\"{2}\"><a href=\"{0}\" ><span>{1}</span> </a></li>"
, target, lbl, lic);
}
正如我说的那样有效但是当我在ADMIN页面中创建一个菜单项时,它会生成菜单项的5个实例,我将向您展示它的外观。(我们有自己的CMS,我们在管理页面中创建所有内容,并在代码中自动添加它们) 。
菜单项 - >首页关于我们关于关于关于我们联系
我的尝试:
我唯一尝试过的是foreach循环。
我被困在这里。
As i said this works but when i create a menu item in the ADMIN page it makes 5 instances of the menu item i will show you down how it looks.(We have our own CMS and we create everything in the admin page and they are added automaticly in the code).
Menu items--> Home About About About About About Contact
What I have tried:
The only thing i have tried is the foreach loop.
I am stuck here.
推荐答案
嗯,显而易见的事情就是这么做正在跳过那些你不需要的东西。但是那时你需要一个标准(在你的场景描述中并不明显)。
Well, the obvious thing to do it is skipping the ones you don't need. But then you need a criterion for that (it is not apparent in the description of your scenario).
这篇关于仅显示一定数量的数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!