2012-09-14 35 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) 
相关问题