gpt4 book ai didi

asp.net-mvc - ASP.NET MVC 3 - 表达式树可能不包含动态操作

转载 作者:行者123 更新时间:2023-12-04 18:12:04 25 4
gpt4 key购买 nike

我得到:表达式树可能不包含动态操作

当我做:

@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)

在 View 的顶部,我的 using 语句类似于: @model x.y.z.Listing

最佳答案

正如消息所说,您在 lambda 表达式中使用了 viewbag,这是一个动态操作:

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

要解决您的问题,只需将动态移出,就像这样
@{
string cultureCode = ViewBag.Languages[i].CultureCode
}

@Html.TextBoxFor(m => m.Translations[cultureCode].Title)

关于asp.net-mvc - ASP.NET MVC 3 - 表达式树可能不包含动态操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12422970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com