I'm new to MVC C#.
Here is a ready and working code (the part of the working code).
@foreach (var item in Model)
{
<div style="height: 200px; ">
@Html.Raw(@item.Description)
</div>
}
The problem is the Description is not displayed on the page in the proper order is. So, the order of <div>
s should be slightly different.
How to modify the code so it works properly?
The order of the Description
field should be ordered by Order
column.
Use OrderBy extension method on IEnumerable in System.Linq namespace
@foreach (var item in Model.OrderBy(i => i.Order))
{
<div style="height: 200px; ">
@Html.Raw(@item.Description)
</div>
}
You can use the Linq OrderBy extension method
@foreach (var item in Model.OrderBy(i => i.Order))
{
}
Directly use orderby
@foreach (var item in Model.OrderBy(i => i.Order))
{
<div style="height: 200px; ">
@Html.Raw(@item.Description)
</div>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With