Solved

MVC 4 showing in the grid

Posted on 2014-10-06
4
209 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
[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
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

734 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