Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mvc5 different row color on table by value

Posted on 2014-03-10
1
Medium Priority
?
655 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 1600 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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