I'm trying to modify the background color of a table row using the code below. However, I'm getting a parser error because the closing tr tag doesn't have a matching opening tr. I tried using @: instead of @Html.Raw(...), but I get the same error. If I type the tr tag outside of the conditional block, it renders a single tag and the table loads fine (just without alternating background colors).

 @foreach (var item in Model)
        if (i % 2 == 0){
            @Html.Raw("<tr style=\"background-color: #c9c9c9\">");

            @Html.DisplayFor(modelItem => item.User)

Related posts

Recent Viewed