Solved

MVC 4 showing in the grid

Posted on 2014-10-06
4
206 Views
Last Modified: 2014-10-20
Hi,
I have a MVC 4 application in place , it is simple just one database and showing the records in the main page. I am a newbie in MVC so,how can I display the records satisfying a data condition in red in my view ?

In my view as below i am just displaying the records in the database but what is the way to show records in RED
if the records date is 7 days or less greater than today's date.

Thanks in advance

 @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Pmam)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)

            </td>
           
            <td>
                @Html.DisplayFor(modelItem => item.Date)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { controller = "Update", Id = item.Id })
                @Html.ActionLink("Delete", "Delete", new { controller = "Update", Id = item.Id },new {style="color: red"})

              @*  @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
                  @Html.ActionLink("Details", "Details", new { id=item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.Id })*@
            </td>
        </tr>

Open in new window

0
Comment
Question by:nicedone
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40365992
You should be able to check the date value, and apply a different style to the text, depending on the criteria.
0
 

Author Comment

by:nicedone
ID: 40367021
@Bob,  I need help and the code to do that if you can
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40367262
Something like this might work:

@{
    var color = Model.Date.Subtract(DateTime.Today).Days < 7 : "red" : "black";
}

...

@Html.DisplayFor(modelItem => item.Description, new { @style = "color: "  + color })

Open in new window

0
 

Author Comment

by:nicedone
ID: 40392206
thank you for your help, i forgot to give you points ,little late but right there :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn how to dynamically set the form action using jQuery.

813 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

16 Experts available now in Live!

Get 1:1 Help Now