2012-12-30 94 views
0

我使用Spark與WPF。這工作正常,我能夠格式化模板,並從自定義的DTO(我的模型)拉標量屬性。我很難找到循環工作。從看the Spark documentation,我應該能夠做到這一點,但我得到的火花例外:For循環Spark視圖引擎/ ASP.NET MVC

Dynamic view compilation failed. 

c:\Users\Echilon\AppData\Local\Temp\tmp4490.tmp(73,73): error CS0103: The name 'Sections' does not exist in the current context 

下面的代碼工作在模板細拉從模型中Name屬性:<h1>${Name}</h1>但for循環生成例外:

<for each="var sect in Sections"> 
    ${#sect.Name} 
    <!-- HTML for each element omitted --> 
</for> 

回答

0

我需要導入的收藏命名空間以及包含在我的IList對象的類型的命名空間:

<use namespace="System.Collections.Generic"/> 
<use namespace="System.Web.Mvc"/> 
<use namespace="MyOtherAssembly"/> 
<viewdata Sections="IList[[ISection]]"/> 
+0

您的基本框架命名空間'System。*'和您的通用用戶命名空間應該在_global.spark中,Web.config中的spark config部分中聲明,或者在構建'SparkViewEngine'時添加到'SparkSettings'中,不必在每個視圖文件中重複它們 –