我需要在另一个循环中执行循环,我得到一个奇怪的错误,好像它缺少关闭}并且我在页面上遇到编译错误。与项目编译相反。错误信息是
CS1513:}预计。
源代码表示1238中的代码行,而页面中的代码不超过150行,真的很奇怪。请帮忙
@using (Html.BeginForm("VCreateCommande", "CCommande", new { id = "formretouche" }, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="control-label col-md-2">Support papier</div>
<div class="col-md-10">
@Html.CheckBoxFor(model => model.Tretouche.Supportpapier, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Tretouche.Supportpapier, "", new { @class = "text-danger" })
</div>
</div>
var i = 1;
foreach (var item in Model.Tformats)
{
var idformat = "idformat" + i;
var idquantite = "qteformat" + i;
var idtxt="qte" + @item.Idformat;
int qteretoucheformat=0;
foreach (var itemretoucheformat in Model.Tretouchesformats)
{
if(itemretoucheformat.IdFormat ==item.Idformat)
{
qteretoucheformat = itemretoucheformat.Quantité;
}
}
<div>
<div class="form-group">
<div class="control-label col-md-2 fltleft">Quantité @item.Format</div>
<div class="col-md-10 fltleft">
@Html.TextBoxFor(model => model.Tretoucheformat.Quantité, new { id = idtxt, Name=idtxt })
@Html.ValidationMessageFor(model => model.Tretoucheformat.Quantité, "", new { @class = "text-danger" })
</div>
</div>
</div>
i = i + 1;
}
<div class="form-group">
<div class="control-label col-md-2">Photo...</div>
<div class="col-md-10">
@Html.TextBoxFor(model => model.Tretouche.fichierphoto, new { type = "file" })
</div>
</div>
<input id="idtyperetouche" name="idtyperetouche" type="text" value="@idtyperetouche" class="hdn" />
<input name="idcommande" type="text" value="@idtyperetouche" class="hdn" />
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Ajouter" class="btn btn-default" />
</div>
</div>
}
<table class="table">
<tr>
<th>Papier</th>
<th>Quantite</th>
<th>Type de retouche</th>
<th>Photo</th>
</tr>
@foreach (var item in Model.Tretouches)
{
var prix = 0;
<tr>
<td>
@Html.CheckBox("Papier", item.Supportpapier)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantite)
</td>
@foreach (var typeretouche in Model.Ttyperetouches)
{
if (item.Idtyperetouche == typeretouche.Idtyperetouche)
{
<td>@typeretouche.Libelle</td>
prix = (typeretouche.Prix * item.Quantite);
}
}
<td>
<img src="@item.SRCphoto" class="">
</td>
<td>
@prix €
</td>
<td>
@Html.ActionLink("Modifier", "Edit", "TRetouches", new { id = item.Idretouche }, null) |
@Html.ActionLink("Supprimer", "Delete", "TRetouches", new { id = item.Idretouche }, null)
</td>
</tr>
}
答案 0 :(得分:4)
对于Razor视图(至少是MVC 4及更早版本),与.cs文件不同,{需要在其自己的行上
foreach (var itemretoucheformat in Model.Tretouchesformats)
{
}
Henk的评论表明,MVC 5可能会有所改进。