Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
   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);
        }




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.
Posted
Updated 13-Mar-19 21:59pm

1 solution

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).
 
Share this answer
 
Comments
simple world 14-Mar-19 8:45am    
Can you help me a bit more? I barly understood what you said.
CPallini 14-Mar-19 8:48am    
Inside the foreach loop you can choose what are the items you need. However, based on the info you provided, I can't tell. So I can't help further.
simple world 14-Mar-19 9:02am    
Could you please explain what else you need to help me ?
I can edit my post but i dont understand what is measing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900