我有三个if
(还尝试了span
,table
和div
),我希望它们按照它们在代码中出现的顺序显示,比如1,2,3
。相反,前两个陈述似乎永远不会保持秩序。
CODE
<div class="row">
@if (item.PastElo.Rank != "None")
{
<img src="~/Content/badges/@(item.PastElo.Rank).png" alt="@(item.PastElo.Rank)" />
}
@if (item.PastElo1.Rank != "None")
{
<img src="~/Content/badges/@(item.PastElo1.Rank).png" alt="@(item.PastElo1.Rank)" />
}
@if (item.PastElo2.Rank != "None")
{
<img src="~/Content/badges/@(item.PastElo2.Rank).png" alt="@(item.PastElo2.Rank)" />
}
</div>
现在,如代码所述,如果某个条件未满足,则无法显示,但无论如何,我的前两个div总是被翻转。
如果我有一组数据,例如
None
Apple
Banana
Peach
我用上面的循环进行了三次迭代,例如
// loop 1
PastElo = Apple
PastElo1 = Banana
PastElo2 = Peach
// loop 2
PastElo = Apple
PastElo1 = Banana
PastElo2 = None
// loop 3
PastElo = Apple
PastElo1 = None
PastElo2 = Peach
它会显示如下。
Banana Apple Peach
Banana Apple
Apple Peach
前两个陈述总是出现反过来。我试过使用div,spans,table,甚至JQuery来插入之前没有运气。
知道为什么会这样吗?
使用MVC和Razer。
谢谢!
问题的实际图像。(注意每个符号中都有一个数字,如果不是null
,则数字应按I,II,III的顺序出现。在我出现在图像之前,我已经完成了第二次箭头。
第二行的输出HTML示例(也显示HTML乱序)
<div class="row">
<img src="/Content/badges/s2diamond.png" alt="s2diamond" height="37" width="37" />
<img src="/Content/badges/s1gold.png" alt="s1gold" height="37" width="37" />
</div>
控制器
public ActionResult Index(string Filter, string searchString, string Sort)
{
ViewBag.champ1 = new SelectList(db.championLists, "ID", "Name");
ViewBag.champ2 = new SelectList(db.championLists, "ID", "Name");
ViewBag.champ3 = new SelectList(db.championLists, "ID", "Name");
ViewBag.elo = new SelectList(db.eloLists, "ID", "rank");
ViewBag.rank = new SelectList(db.rankLists, "ID", "rank");
ViewBag.role1 = new SelectList(db.roleLists, "ID", "lane");
ViewBag.role2 = new SelectList(db.roleLists, "ID", "lane");
ViewBag.s1elo = new SelectList(db.PastEloes, "ID", "Rank");
ViewBag.s2elo = new SelectList(db.PastEloes, "ID", "Rank");
ViewBag.s3elo = new SelectList(db.PastEloes, "ID", "Rank");
ViewBag.s4elo = new SelectList(db.PastEloes, "ID", "Rank");
// !filter and !sort
if (String.IsNullOrEmpty(Sort) && (String.IsNullOrEmpty(searchString) || String.IsNullOrEmpty(Filter)))
{
return View(db.Users.ToList().OrderBy(x => x.name));
}
}