I have the following code and I want to put the table headers outside of the @foreach but when i move it outside It no longer sees the closing tag. Thanks
@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 />
}
So this is kinda what I’m trying to accomplish, but it keeps giving me errors no matter what way I try it.
<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 />
}
You must have your table closing tag outside of the for each loop.