asp.net-mvcrazorrazor-2

Special characters after syntax


I would like to know how to and is it posible to add special charaters after Razor syntax.

Example:

@Html.Raw(Model.Text)()

The problem is with () at the end. I'd like to add it just after generated content.


Solution

  • As an alternative to the <text></text> markup, you can simply wrap your Html.Raw statement in parenthesis. Example:

    @(Html.Raw(Model.Text))()

    This will prevent razor from trying to parse the extra set of parenthesis as they help razor determine when to stop parsing the markup.