Solved

mvc5 different row color on table by value

Posted on 2014-03-10
1
638 Views
Last Modified: 2014-03-13
I'm trying to change the row color of a table based on if statements. I've tried if else in razor, but I'm getting syntax errors.

@foreach (var item in Model.List)
                                            {
                                                DateTime dadate = item.G.StatusDate;
                                                TimeSpan days = dadate - DateTime.Now;
                                                if (days.Days < 1)
                                                {
                                                   @:
                                                    <tr class="info">
                                                }
                                                else
                                                {
                                                 @:   
                                                <tr class="warning">
                                                }


                                                <td>
                                                  @Html.DisplayFor(modelItem => item.G.RequestID)
                                                </td>
                                                <td>
                                                    @Html.DisplayFor(modelItem => item.T.ItemDescription)
                                                </td>
                                            </tr>
                                            }

Open in new window

0
Comment
Question by:NickMalloy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

Accepted Solution

by:
Sammy earned 400 total points
ID: 39919086
You need to use Html.Raw like this

if (days.Days < 1)
                                                {
                                                   @Html.Raw(" <tr class="info">");
                                                }
                                                else
                                                {
                                             
                                            @Html.Raw(" <tr class="warning">");
                                                }

                                                   <td>
                                                  @Html.DisplayFor(modelItem => item.G.RequestID)
                                                </td>
                                                <td>
                                                    @Html.DisplayFor(modelItem => item.T.ItemDescription)
                                                </td>
                                            </tr>
                                            }

Open in new window

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question