我真的建议将该逻辑推入您的模型中,然后获取已经为视图格式化的数据:
[Serializable]
public class YourModel
{
private int _mid
{
get { Categories.Count / 2; }
}
private int _top
{
get { Categories.Count - _mid; }
}
public List<Category> CategoriesLowerHalf
{
get { Categories.OrderBy(i => i.CategoryName).Take(_mid); }
}
public List<Category> CategoriesUpperHalf
{
get { Categories.OrderBy(i => i.CategoryName).GetRange(_mid, _top); }
}
// rest of your model
}
那么在你看来:
@foreach (var category in Model.CategoriesLowerHalf)
{
<li>
<div id="category_@(category.SKU)" class="itemBlock" onclick="toggle('@(category.SKU)')">category.Name</div>
</li>
}
@foreach (var category in Model.CategoriesUpperHalf)
{
<li>
<div id="category_@(category.SKU)" class="itemBlock" onclick="toggle('@(category.SKU)')">category.Name</div>
</li>
}