I am new with web development and MVC, I have a Driver model, with public LastEyeCheck { get; set; }
property, and in index.cshtml
there is a table of drivers.
My question: I want to color in red the row with driver that past 5 months since his last eye check, how can I do that? where should I add the rquired code? in the index.cshtml
? in the model
? in the controller
?
Driver model:
public class Driver
{
[Key]
public int LicenceID { get; set; }
public string FirstName { get; set; }
....
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime LastEyeCheck { get; set; }
[EmailAddress]
public string Email { get; set; }
}
public class DriverDBContext : DbContext
{
public DbSet<Driver> Drivers { get; set; }
}
index.cshtml:
@model IEnumerable<try4.Models.Driver>
@{
ViewBag.Title = "Index";
}
<script src="~/Scripts/MyJs.js"></script>
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
....
<th>
@Html.DisplayNameFor(model => model.LastEyeCheck)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
....
<td>
@Html.DisplayFor(modelItem => item.LastEyeCheck)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.LicenceID }) |
@Html.ActionLink("Details", "Details", new { id=item.LicenceID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.LicenceID })
</td>
</tr>
}
</table>