Solved

mvc5 different row color on table by value

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now