Solved

MVC 4 showing in the grid

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Download a website to hdd 2 49
Message not shown 5 31
Put shading on half of picture 8 23
Not seen Link button 5 14
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…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 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

22 Experts available now in Live!

Get 1:1 Help Now