我有以下代碼,我想將表標題放在@foreach之外,但是當我將它移到外面時,它不再看到結束標記。由於獲取不正確的剃刀語法錯誤
@foreach (var item in Model)
{
<div class="data" ><label for="fullName" >Name: </label>@item.UserName.Replace('.', '')</div>
if (Model.Count > 0)
{
<table class="data">
<tr>
<th>
Work Date
</th>
<th>
Change Details
</th>
<th>
Ip Address
</th>
<th></th>
</tr>
<tr>
<td>
@{
var stringDate = item.WorkDate.ToShortDateString();
}
@Html.DisplayFor(modelItem => stringDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ChangeDetail)
</td>
<td>
@Html.DisplayFor(modelItem => item.IpAddress)
</td>
</tr>
</table>
}
<br />
<hr />
}
所以這是有點什麼,我試圖完成,但它一直給我的錯誤,不管什麼辦法,我試試吧。
<table class="data">
<tr>
<th>
Work Date
</th>
<th>
Change Details
</th>
<th>
Ip Address
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<div class="data" ><label for="fullName" >Name: </label>@item.UserName.Replace('.','')</div>
if (Model.Count > 0)
{
<tr>
<td>
@{
var stringDate = item.WorkDate.ToShortDateString();
}
@Html.DisplayFor(modelItem => stringDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ChangeDetail)
</td>
<td>
@Html.DisplayFor(modelItem => item.IpAddress)
</td>
</tr>
</table>
}
<br />
<hr />
}
哇我覺得無知已經搞亂了20分鐘。謝謝 ) – Jesse