Search code examples
c#asp.netvisual-studiorazorblazor

Why does Visual Studio highlight double curly braces in Razor (.cshtml/.razor)?


Although I have been working with Razor pages(.cshtml) and Razor components(.razor) in Blazor for a while in Visual Studio 2019, I did not stumble upon this feature up until now where it highlights anything between two pairs of braces: {{ }}.

It does it for both Razor pages(.cshtml) and Razor components(.razor). There is no mention of such syntax in the Razor syntax documentation. What purpose was the {{}} syntax intended to serve? What am I missing?

This is what it looks like. The text is highlighted in hot pink:

The highlighted text between double braces.

This is what the same highlight looks like in the light theme:

The highlighted text in light theme


Solution

  • This is mapped by the "HTML Client Template Value" setting in Tools|Options.

    It is a piece of HTML syntax used in a.o. Angular for data-binding,
    like <h1> {{user.username}} </h1>. Comparable to Blazor's yellow @

    I don't think this has any meaning in a Blazor (razor) file. Safe to ignore.