26.06.2017 Views

Bootstrap for ASP.NET MVC

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using <strong>Bootstrap</strong> CSS and HTML Elements<br />

Of course, we can also apply these styles dynamically in our <strong>ASP</strong>.<strong>NET</strong> <strong>MVC</strong> views.<br />

In our ProductViewModel view model, we have a Status property, which can be<br />

one of the ive contextual <strong>Bootstrap</strong> classes. By setting the element's class to<br />

this property, we can dynamically change the color of the rows in the table, based<br />

on their data as illustrated in the following markup:<br />

<br />

@<strong>for</strong>each (var item in Model)<br />

{<br />

<br />

<br />

@Html.DisplayFor(modelItem => item.ProductName)<br />

<br />

<br />

@Html.DisplayFor(modelItem => item.UnitPrice)<br />

<br />

<br />

@Html.DisplayFor(modelItem => item.UnitsInStock)<br />

<br />

<br />

@Html.DisplayFor(modelItem => item.Discontinued)<br />

<br />

<br />

@Html.ActionLink("Edit", "Edit", new { /* id=item.<br />

PrimaryKey */ }) |<br />

@Html.ActionLink("Details", "Details", new { /*<br />

id=item.PrimaryKey */ }) |<br />

@Html.ActionLink("Delete", "Delete", new { /* id=item.<br />

PrimaryKey */ })<br />

<br />

<br />

}<br />

<br />

In the preceding code, you will notice how the table row's class was set to @item.<br />

status. This will cause the rows to be highlighted based on the mapping we've<br />

speciied <strong>for</strong> the Status property, as illustrated in the following screenshot:<br />

[ 38 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!