我有以下代码,我想将表标题放在@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