4
@if (Model.Property != null)
{
    <text>
        <div class="row">
    </text>
    Html.RenderPartial("~/Views/CustomView.cshtml", Model);
    <text> (line throwing error)
        </div>
    </text>
}

Error: "The "text" element was not closed. All elements must be either self-closing or have a matching end tag."

I struggle to understand why second set of <text> tags is returning that error. Any help to understand it would be appreciated.

Chris Hermut
  • 1,708
  • 3
  • 17
  • 32

2 Answers2

5

In Razor, tags must be nested properly. <text></div></text> is not proper nesting.

I think in your case you simply should remove all the <text> and </text> tags:

@if (Model.Property != null)
{
    <div class="row">
        @Html.Partial("~/Views/InTimeTemplate/InputFormElements/ReadMore.cshtml", Model);
    </div>
}

Which is equivalent to:

@if (Model.Property != null)
{
    <div class="row">
        @{
            Html.RenderPartial("~/Views/InTimeTemplate/InputFormElements/ReadMore.cshtml", Model);
        }
    </div>
}
  • Partial will return the result, which will be rendered thanks to the @
  • RenderPartial will render it directly, but you need to introduce a C# block with @{ ... }
Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
0

Bit too late but still:

Just as an example u can use "@:"

Like this:

@for (int t = 0; t < Model.TrainLines[i].Stations.Count; t++)
            {
                <circle id="pointA" cx="@stationCounter" cy="@trainLineCounter" r="3" />
               @: <text x="@stationCounter" y="@trainLineCounter" dy="30">A</text>
                stationCounter += 50;
            }
vsarunov
  • 1,433
  • 14
  • 26