Lion
Lion

Reputation: 17898

ASP.NET RazorGenerator "WriteAttribute" is not defined

I'm using RazorGenerator https://github.com/RazorGenerator/RazorGenerator to outsource my menu to a DLL file so that I can share it across multiplice projects. In those views I've a foreach loop which should generate a list like this:

@foreach (var myItem in MyClass.Instance.Elements) {
    <li>
        <img src="@myItem.Icon" />
    </li>
}

But I can't compile them: The MyView.generated.cs file which is generated by RazorGenerator is creating the following line for the img tag:

WriteAttribute("src", Tuple.Create(" src=\"", 1038), Tuple.Create("\"", 1057)

Here is the problem because I got an error that 'WriteAttribute' is not defined. I can't find many information about this method, seems like that this is a method from RazorGenerator.

The strange thing is that I tested the same code before in a testproject because it's the first time I'm using RazorGenerator. There it works with the same loop but I can't find out any differences. Both projects have the same references and assemblys also in the same version. I ony found out that WriteAttribute() came from WebPageExecutionBase.

How can I fix the issue?

Upvotes: 2

Views: 898

Answers (2)

listylister
listylister

Reputation: 11

Don't set the Build Action to none as suggested above as your local copy will not generate the correct generated.cs file.

Upvotes: 0

Lion
Lion

Reputation: 17898

By checking every package in both projects I found out that the NuGet-Package Microsoft.ASP.NET.WebPages was installed in an outdatet version. Can't figure out why because I used the "Update all" button in the NuGet-Manager of the project as I did in the testing-project and no errors were shown. I updatet the package using the NuGet-Console to the latest version which is 3.1.2 at the time I write this post and now it worked like expected.

Upvotes: 1

Related Questions