cunelson3 Posted January 25, 2016 Share Posted January 25, 2016 I'm practicing and trying to write a table varying the opening row tags: @foreach(blah in blahs) { if (condition){ @Html.Raw('<tr>'); } else { @Html.Raw('<tr class="shaded">'); } // More row stuff here </tr> } Is there a way to do this? My editor keeps complaining about a missing <tr> tag. Is it possible to add a class to a tag using razor? What's the common practice? BTW, this is an incredible web site! Link to comment Share on other sites More sharing options...
dsonesuk Posted January 25, 2016 Share Posted January 25, 2016 Its probably complaining because it sees the HTML </tr> tag, but does not see html <tr> tag to go with it, because it is produced by coding. But! If you then produce </tr> by coding it will then complain that there is no <tr> OR </tr>, if you can code it to just insert class when required in <tr> tag instead @foreach(blah in blahs) { variable = ''; if (condition){ variable='class="shaded"'; } <tr insert variable> // More row stuff here </tr> } It would have less reason to complain. 1 Link to comment Share on other sites More sharing options...
cunelson3 Posted January 26, 2016 Author Share Posted January 26, 2016 I'll give it a try. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now