SparkViewEngine / spark

Spark is a view engine for ASP.NET MVC and Castle Project MonoRail frameworks. The idea is to allow the html to dominate the flow and any code to fit seamlessly.
Apache License 2.0
260 stars 86 forks source link

The name 'group' does not exist in the current context #56

Closed autonomatt closed 9 years ago

autonomatt commented 9 years ago

I have an error I haven't come across before, and I'm stuck on it. I have the following markup in a spark view:

<table each="var group in Model.VariantGroups">
    <p>${group.Key}</p>
</table>

This throws the error "The name 'group' does not exist in the current context". This is a redesign, so I have an existing view with pretty much the same markup and this works. I have tried <for each="..."> instead but get the same error.

Any ideas would be much appreciated.

RobertTheGrey commented 9 years ago

I wonder if the word group is somehow reserved because of a LINQ thing. Can you try rename to grp and see if the same error occurs. The syntax looks right to me

autonomatt commented 9 years ago

Didn't work. Very odd as I have another view that works. It's a _Partial.spark just in case that makes a difference. It looks like it's just not processing the each attribute. I'll keep digging...

autonomatt commented 9 years ago

Yeah, so I've set the Model.SomethingThatDoesNotExist and it doesn't throw an error on this, so it's definitely not processing this statement for some reason...

RobertTheGrey commented 9 years ago

What if you add some arbirtrary List<string> to the Model like Model.TestSomeKeys - does it cycle through those?

autonomatt commented 9 years ago

Found the source of the bug. There was an unclosed <th> element in the head of the table. Suspected something like this, just couldn't see it.

RobertTheGrey commented 9 years ago

Ah ok cool - thanks for letting me know. Glad you fixed it.