I have a list of elements that I want to display as the contents of the main one (the main one is not included below). Each element has 3 attributes: section name, label and value. Each element is enclosed in and every time a section changes. I need to open (and close the previous one, if any). I am using a Razor view with this code:
@foreach (LocalStorageItem lsi in Model) { string fld_name = "f_" + lsi.ItemName; if (lsi.SectionName != sn) { if (sn != "") { Html.Raw("</fieldset>"); } sn = lsi.SectionName; <h2>@sn</h2> Html.Raw("<fieldset>"); } <div class="row"> <div class="ls_label">@lsi.ItemName</div> <div class="ls_content" name="@fld_name" id="@fld_name">.</div> </div> } @if (Model.Count != 0) { Html.Raw("</fieldset>"); }
The problem is this: every time the section name changes, the fieldset tag (open and / or closed) is not generated. Where am I mistaken? If I do not use Html.Raw (or @: as an alternative), the VS2010 parser signals an error.
razor
gattox
source share