最初に使用したとき、私はそれを気に入って、Webフォーム<%:%>などビュー・エンジン のように混乱しました。 「{」かっこが置かれている場所や他のシナリオに過敏であることに気付くことはできません。これは、古いビューエンジンが厄介ではない点でエラーを出します。カート・インデックス・ビュー(Razorビュー・エンジン)のRazor構文に関する助けが必要
たとえば、フォームヘルパーの閉じ括弧} が</table>
タグの下にあるため、次のコードではエラーが発生します。私がそれを</tbody>
の上に置くとうまくいきます!しかし、サブミットボタン入力がネストされていなければならず、ボタン入力をテーブルに入れたくないので、 は必要ありません。
@model CartTest.Models.Cart
@{
ViewBag.Title = "Index";
}
<h2>Cart Index</h2>
<table width="80%" align="center">
<thead>
<tr>
<th align="center">Quantity</th>
<th align="left">Item</th>
<th align="right">Price</th>
<th align="right">Subtotal</th>
</tr>
</thead>
<tbody>
@{int index = 0;}
@using (Html.BeginForm("UpdateCart","Cart"))
{
foreach (var line in Model.Lines)
{
<tr>
@Html.Hidden("Lines.Index", index)
<td align="center">@Html.TextBox("Lines[" + index + "].Quantity", line.Quantity)</td>
<td align="left">@line.Product.Name</td>
<td align="right">@line.Product.Price</td>
<td align="right">@(line.Quantity * line.Product.Price)</td>
<td align="right">@Html.ActionLink("Remove", "RemoveItem", new { productId = line.Product.ProductID }, null)</td>
</tr>
index++;
}
</tbody>
<tfoot></tfoot>
</table>
<input type="submit" value="Update Cart" />
}