我想通过一组数字循环并在记分卡上显示它们。如果我逐句通过代码,变量返回正确的值,我无法让它们显示。试图在C#中使用剃须刀的for循环中显示变量/ Linq
@foreach (var g in Model)
{
@Html.Raw(string.Format("<tr>"))
int grossScore = 0;
@Html.Raw(string.Format("<td>{0}</td>", g.PlayerName))
for (int s = 0; s < 18; s++)
{
@Html.Raw(string.Format("<td>"));
int holescore = 0;
var bretak = @g.Scores.Take(1).Skip(s).FirstOrDefault();
var werwee = @g.Scores.Where(b => b.Hole == s + 1).Select(i => i.Score).FirstOrDefault();
//if (bretak.Score > 0)
//{
// holescore = bretak.Score;
//}
holescore = werwee;
Html.Raw(string.Format("{0}", holescore));
//@Html.ToString(holescore);
//Html.Raw(holescore);
@Html.Raw(string.Format("<td>" + @holescore + "</td>"));
grossScore = grossScore + holescore;
@Html.Raw(string.Format("</td>"));
}
@Html.Raw(string.Format("<td>{0}</td>", grossScore))
@Html.Raw(string.Format("<td align=\"center\"> <button type=\"button\" class=\"btn btn-default btn-xs editBtn\" data-player-id=\"'{0}'\">Edit </button></td>", g.GameId))
@Html.Raw(string.Format("<td> <button type=\"button\" class=\"btn btn-default btn-xs deleteBtn\" data-player-id=\"'{0}'\">Delete </button></td>", g.GameId))
@Html.Raw("</tr>")
}
玩家名称正确显示,grossscore变量可以正确计算和显示。我从循环中获得正确数量的盒子,但holecore不会显示。对不起,它可能看起来有点混乱,但我留下了一些代码来展示我尝试过的一些东西。
'开始添加@ holecore'是通过'holescore = werwee;'设置的,所以确保'werwee'不是'null' – CodeNotFound
它在第四洞后是空的,但是洞1-4都有有效的数据。 –
如果你想显示它,那么使用' @ holescore '。 –
CodeNotFound