I'm having fun with Razor today! Can you see what is wrong with this view and explain why it errors?
@foreach (var item in Model){
if (item.ID != PreviousOrderId){
<div class="orderdetail">
<div class="customer">
<p class="strong">OrderID:</p>
<p>@item.ID</p>
<p class="strong">Order Date:</p>
<p>@String.Format("{0:g}", TimeZoneInfo.ConvertTime(item.DateInitialised, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time")))</p>
<p class="strong">Customer Name:</p>
<p>@item.WebsiteUser.Name</p>
<p class="strong">Practice Name:</p>
<p>@item.WebsiteUser.PracticeName</p>
<p class="strong">Customer E-Mail:</p>
<p>@item.WebsiteUser.EMailAddress</p>
</div>
}
<div class="detail">
<span class="strong">Licence Key:</span><span>@item.Licence.LicenceKey</span>
<span class="strong">Serial No:</span><span>@item.Licence.SerialNumber</span>
</div>
@if (item.ID != PreviousOrderId && PreviousOrderId != 0){
</div>
<div class="clear"></div>
}
PreviousOrderId = item.ID;
}
You have divided <div class="orderdetail">
into two pieces. Opening tag is in first if
block, closing tag is in second if
block.
This is something confusing for Razor, I think.
Try to open and close your div
in one if
block.
if you already are inside a code-block you dont need to @-prefix code constructs anymore...your code block starts with @foreach.
@foreach (var x in new string[] { "x", "y" ])
{
if (userGuid != ViewBag.x)
{
@:<div class="orderdetail">
<div class="customer">
<p class="strong">OrderID:</p>
<p>@item.ID</p>
<p class="strong">Order Date:</p>
<p>@String.Format("{0:g}", TimeZoneInfo.ConvertTime(item.DateInitialised</p>
<p class="strong">Customer Name:</p>
<p>@item.WebsiteUser.Name</p>
<p class="strong">Practice Name:</p>
<p>@item.WebsiteUser.PracticeName</p>
<p class="strong">Customer E-Mail:</p>
<p>@item.WebsiteUser.EMailAddress</p>
</div>
}
<div class="detail">
<span class="strong">Licence Key:</span><span>@item.Licence.LicenceKey</span>
<span class="strong">Serial No:</span><span>@item.Licence.SerialNumber</span>
</div>
if (userGuid != ViewBag.x && ViewBag.x != 0)
{
@:</div>
<div class="clear"></div>
}
PreviousOrderId = item.ID;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With