Solved

mvc5 different row color on table by value

Posted on 2014-03-10
1
641 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 Ageil 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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