Solved

MVC 4 showing in the grid

Posted on 2014-10-06
4
201 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

760 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

26 Experts available now in Live!

Get 1:1 Help Now