我在使用Razor視圖的ASP.NET MVC3項目中使用Linq to SQL。ASP.NET MVC Razor視圖,未正確顯示Linq to SQL相關實體
我的L2S對象似乎在控制器/模型代碼中工作正常;我可以參考和使用我的相關對象的子類集合。但是,在我的剃刀視圖中,我無法這樣做。智能感知識別子類集合:
Model.ChildObjects
但它無法提供任何代碼完成的ChildObjects
對象本身。要使用該集合作爲像這樣的集合:
foreach(var item in Model.ChildObjects)
導致以下聯錯誤在編輯器:
foreach statement cannot operate on variables of type
System.Data.Linq.EntitySet<ChildObjectType> because
System.Data.Linq.EntitySet<ChildObjectType> does not
contain a public definition for 'GetEnumerator'
似乎是壞了什麼被從Razor視圖引用。當我嘗試使用這樣的代碼:
@Model.ChildObjects.Count()
我在執行得到這個編譯錯誤:
The type 'System.Data.Linq.EntitySet`1<T0>' is defined in an assembly that is
not referenced. You must add a reference to assembly
'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我並沒有改變在web.config
文件(S)爲項目什麼。我最近更新了我的Windows 7 SP1,並更新了我的NuGet ...但我不確定是否會有任何涉及的內容。
這沒有幫助;事實上,在編譯相關命名空間不存在的視圖時,它給了我一個錯誤。 –