KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to set up a dropdown menu that pulls from a Datatable. This works just fine for the first level of the menu. Working code: <ul class="dropdown-menu"> @foreach (System.Data.DataRow dr in menu.Rows) { if (Level1 != dr["Level1"].ToString()) { <li><a href="#">@dr["Level1"].ToString()</a></li> Level1 = @dr["Level1"].ToString(); } } </ul> The problem occurs when I try to add a nested if statement. If you put this code into Visual Studio you will notice that the closing bracket for the @foreach loop is not recognized by Razor. Code breaks: <ul class="dropdown-menu"> @foreach (System.Data.DataRow dr in menu.Rows) { if (Level1 != dr["Level1"].ToString()) { <li><a href="#">@dr["Level1"].ToString()</a></li> Level1 = @dr["Level1"].ToString(); if (Level2 != dr["Level2"].ToString()) { <li><a href="#">@dr["Level2"].ToString()</a></li> Level2 = @dr["Level2"].ToString(); } } } <!-- the issue is the bracket on this line --> </ul>
Tags (comma-separated)
Save Edits
Cancel