My question is where to put the logic for the table data that is getting returned.
I'm playing with a tutorial that shows courses and enrollments for students.
here is the data from the screen
Grade Title LastName
2.00 Economics Tibbetts Edit | Details | Delete
3.50 Economics Guzman Edit | Details | Delete
4.00 Literature Catlett Edit | Details | Delete
1.80 Literature Tibbetts Edit | Details | Delete
3.20 Chemistry Tibbetts Edit | Details | Delete
4.00 Chemistry Guzman Edit | Details | Delete
4.00 Literature Pete Edit | Details | Delete
the code started out just showing the table data
@foreach (var item in Model.Enrollments)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Course.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Grade)
</td>
<td>
@Html.DisplayFor(modelItem => item.Course.Credits)
</td>
</tr>
}
I was able to change the tr background red if the grade was <=2 by adding the vars style and style="@style" ( found this on stack overflow)
@foreach (var item in Model.Enrollments)
{
var style = item.Grade <= 2 ? "background-color:Red" : null;
<tr style="@style">
<td>
@Html.DisplayFor(modelItem => item.Course.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Grade)
</td>
<td>
@Html.DisplayFor(modelItem => item.Course.Credits)
</td>
</tr>
}
Is this correct, because it is on the view and how would I do something harder like remove the delete action for a title of Economics or not show the user lastname
if it starts with a "T"
Is this all supposed to be in a PartialView or a controller or both and how to do this.
An example would be great. I guess I just don't understand how to massage the data before it gets to a view.
I'm a classic asp doer moving to MVC. I'm realize there is supposed to be a separate of code so that it's not spaghetti like classic, but I'm a newbie and am confused on how to do so. In the old days I would do an if statement and do the logic and then just execute asp and or html based on that.