我有
的车型数据库中的列表
我过去曾经使用过类似的东西。排序列表的顺序以在视图中表示。
@ {var veh =(IEnumerable)ViewBag.Vehicles; veh = veh.OrderByDescending(v => v.Name!=" Other")。ThenBy(v => v.Name);}
现在我想按以下顺序显示结果。
在"其他"之前的列表中排序按照排序的字母顺序跟进左侧列表。最后用"其他"
我希望我能解释得更好。任何帮助深表感谢。感谢
答案 0 :(得分:1)
@{var veh = (IEnumerable<Vehicle>)ViewBag.Vehicles; veh = veh.OrderByDescending(v => v.Name != "Other").ThenBy(v => Convert.ToInt32(v.IsActive)==0).ThenBy(v=>v.Name);}
@foreach (Vehicle v in veh)
{
<div class="col-xs-4">
<input type="checkbox" name="VehicleId" value="@v.VehicleId" id="@v.VehicleId" />
<span for="@v.VehicleId">@v.Name</span><br />
</div>
}
答案 1 :(得分:0)
这在查询中使用外部变量有点欺骗,但它有效..
var cars = new string[] {"Audi", "Hyndai", "Toyota", "Marcedes",
"Other", "Accura", "Subaru", "Honda"};
int seen = 0;
var list = from car in cars
let order = (car=="Other") ? seen=2 : (seen==2 ? 1 : 0)
orderby order, car
select car;
list.Dump();