2012-09-14 34 views
1

我得到:表達式樹不能包含一個動態操作ASP.NET MVC 3 - 一個表達式樹不能包含一個動態操作

當我這樣做:

@Html.TextBoxFor(m => m.Translations[ViewBag.Languages[i].CultureCode].Title) 
<br/> 
@Html.TextBoxFor(m => m.Translations[ViewBag.Languages[i].CultureCode].PreviewDescription) 
<br/> 
@Html.TextBoxFor(m => m.Translations[ViewBag.Languages[i].CultureCode].FullDescription) 

我做的簡單TextBoxFor的早期,如:

@Html.TextBoxFor(m => m.ContactName) 
@Html.TextBoxFor(m => m.EmailAddress) 

在視圖的頂部,我使用語句類似於:@model x.y.z.Listing

回答

0

我想,你必須檢查你使用的是非常類型的視圖。

+0

這可能會更好地作爲評論,但它仍然是一個好點。 – WEFX

3

正如消息說,你正在使用viewbag,這是一個動態操作,在您的lambda表達式:

@Html.TextBoxFor(m => m.Translations[ViewBag.Languages[i].CultureCode].Title) 

爲了解決你的問題,只需將動態的,這樣

@{ 
    string cultureCode = ViewBag.Languages[i].CultureCode 
} 

@Html.TextBoxFor(m => m.Translations[cultureCode].Title) 
相關問題