Building a quick view that will display a list of all days but only render a header when the day of week changes. Why am I getting a syntax error by the foreach? Any help would be greatly appreciated!
@{
int lastDay = 0;
}
@foreach (var grouping in Model.EventTemplate.EventTemplateSlots) {
if (grouping.Day != lastDay) {
if (lastDay != 0) {
</div>
}
<div style="margin: 5px;"><div class="ui-widget-header ui-corner-all" style="padding: 5px;">@(((DateTime)Model.StartDate).AddDays(grouping.Day).ToShortDateString())</div>
lastDay = grouping.Day;
}
}
Razor does not work this way. HTML elements cannot be disjoined as you have it. You have a naked
</div>:This is invalid as the HTML tags need to be matched similarly to C# braces (they need to be at the same level of nesting and the end tag cannot appear lexically before the start tag). It’s not clear to me why you are using that
lastDaycheck. Why not write it without it like this instead?This way the start/end HTML tags match up as they need to.