?
Solved

MVC 4 showing in the grid

Posted on 2014-10-06
4
Medium Priority
?
214 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 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

762 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