Razor: tag within conditional statement throwing error

@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.


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> }
    <li>Partial will return the result, which will be rendered thanks to the @</li> <li>RenderPartial will render it directly, but you need to introduce a C# block with @{ ... }</li> </ul>


    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; }


  • How to update powerpivot pivot table filter via cell reference?
  • VBScript to check for open process by user
  • Unable to run SDL program in Eclipse but able to do so in Windows Explorer
  • Dependable views in Ember
  • Regex for Specific Tag
  • Avoid registering duplicate broadcast receivers in Android
  • Java making confirming exit
  • How do I Dispose a HttpResponseMessage in my Web Api Method?
  • C# fibonacci function returning errors
  • Not able to aggregate on nested fields in elasticsearch
  • C: Incompatible pointer type initializing
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Swift: Switch statement fallthrough behavior
  • Custom Tabgroup Appcelerator
  • Get one-time binding to work for ng-if
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Projection media query: browser support and workarounds?
  • Different response to non-authenticated users and AJAX calls
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Volley JsonObjectRequest send headers in GET Request
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • When should I choose bucket sort over other sorting algorithms?
  • Importing jscolor library in angular 2
  • Build own AppleScript numerical error handling
  • Weird JavaScript statement, what does it mean?
  • Websockets service method fails during R startup
  • Google cloud sdk not working when python points python3
  • Unanticipated behavior
  • Is there a mandatory requirement to switch app.yaml?
  • C# - Getting references of reference
  • Hits per day in Google Big Query
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Django query for large number of relationships