2

Resolved

WriteAttributeTo

description

Razor Generator doesn't seem to allow me to write variables inside of things like href="@variable", similarly with style attributes and such. The generated code certainly used to work, and nothing has been changed but it breaks if I generate the compiled view again. The method below is used in the regeneration:

WriteAttributeTo(__razor_helper_writer, "href", Tuple.Create(" href=\"", 1390), Tuple.Create("\"", 1464)
//does not exist in the current context

Where as before there was only WriteLiteralTo and WriteTo in the code, no WriteAttributeTo:

WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <span class=\"tag\">\r\n <a href=\"");

line 58 "....\Extensions\Helpers\ListHelpers.cshtml"

comments

pranavkm wrote Dec 17, 2012 at 5:04 PM

We look at the assembly references to figure out what version of the Razor parser to use. Are you trying to build a Mvc 4 application? If so, then the generated output is what the v2 Razor parser produces and it must be a breaking change in it.

Steji wrote Dec 18, 2012 at 10:02 AM

Yes, I am using MVC 4 in the application. Does Razor Generator support MVC 4 at the moment? Are there known issues with it?

davidebbo wrote Dec 18, 2012 at 5:45 PM

Does your view work correctly if you don't use RazorGenerator?

And if you look at the generated code, what specific class is your view extending (including the version of the assembly it comes from)?

pranavkm wrote Dec 18, 2012 at 5:56 PM

That does look like the right format for attribute generation in Razor v2. Like Ebbo mentioned, might be worth verifying if there's a bug in the parser by running the page without the generator.

robdmoore wrote Dec 20, 2012 at 7:01 AM

My team is getting this as well after upgrading from RazorGenerator from 1.4.3 to 1.5.0.

I've copied the file contents to a normal view file and viewed the page to ensure that the problem is definitely not the content in the page. I'm using @* Generator: MvcHelper *@ so the class doesn't extend anything - it's just a static class.

davidebbo wrote Dec 20, 2012 at 3:55 PM

Would be great to get a small runnable repro app here so we could investigate. There are many different ways to run RazorGenerator, and that would remove all ambiguities.

robdmoore wrote Jan 2, 2013 at 2:18 AM

I've figured out the problem (at least what was causing it for my team)!

If you put @using statements above the @* Generator: MvcHelper *@ comment then it happens.

I've pushed a repro here: https://github.com/robdmoore/RazorGeneratorIssue89

Steji wrote Jan 2, 2013 at 9:37 AM

That has fixed it for me too, cheers Rob! I had using statements but no @* Generator: MvcHelper *@ comment. Putting that comment in above the using statements did the trick.

pranavkm wrote Jan 14, 2013 at 2:17 AM

Fixed in changeset 7052aaae4b58