我想通過一組數字循環並在記分卡上顯示它們。如果我逐句通過代碼,變量返回正確的值,我無法讓它們顯示。試圖在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