Template Markup and Razor Problem

Sep 18, 2012 at 9:44 AM


I have the following code:

@* Generator: Template *@

@functions {
  public dynamic Model { get; set; }
  public Boolean UseHtml { get; set; } 

@if (UseHtml) {
  <div>Hello @Model.Name</div>
} else {
  Hello @Model.Name

On the second "@Model.Name" I get the following error: "; expected".

I tried a few changes but I keep getting errors when using some more complex markup.

Any idea how to solve this?

Thank You,


Sep 18, 2012 at 4:16 PM

That's how Razor works. Unless you begin some form of tag, you're still in C# code. @Foo is a valid expression to represent a member named Foo. You'd instead need to wrap it in some form of tag

Hello <text>@Model.Name</text>

Sep 18, 2012 at 4:23 PM

Generally, if you run into this type of issues, first thing to try is to do the same in a regular page without RazorGenerator. This way, it can help isolate general Razor questions from RazorGenerator issues.