I’m a MVC Noob and I need some help cleaning up my code.
I have a index view (Razor and VB.NET) that is supposed to return the last 3 items in my model. This is what I did. It works, but It looks ugly and I’m sure there is a better way of doing it. Please help.
My View
For i As Integer = (Model.Count.ToString() - 3) To (Model.Count.ToString() - 1)
Dim currentItem = Model(i)
@<tr>
<td>...do some stuff with my currentItem</td>
</tr>
Next
If Model is an Enumerable of something, then you can use Linq extension methods to do something like this (in C#, I don’t do VB)
If you need them in the original order, you can always Reverse() again afterwards.
Although, if you aren’t going to use the rest of the elements, then you should actually do this in your controller, or business layer and only return the three elements.