Maybe I missed something. This seems to work for html or css. As far as I can figure out, there are several ways to approach this depending on your requirements.
In a line by line (i.e. you will never know what colors will be until they are defined somewhere in the application or in the database where the static storage of the value is not statically), set the html style <tr style='background-color: @Model.Colour'> in the line to set background-color to the desired color.
Based on the type / state (i.e. you know what colors will be ahead of time, but not which rows they will be assigned), I would define a class for each row: <tr class='@Model.Type'> and then assign background-color to your CSS class with the same name as the value in Model.Type.
To get this color / type, you will want to convey it using your model. Perhaps you already have this property on your model, I donβt know.
For simple alternating patterns, simply use this technique or selector :nth-child(odd) and :nth-child(even) css.
Sometimes the simplest solutions are the best solutions.
source share