我收到以下错误:
表达式树可能不包含动态操作
以下是模型:
public class ProjectType
{
public string Project { get; set; }
public string Name { get; set; }
public string Server { get; set; }
}
public class ProjectTypesViewModel
{
public int SelectedId { get; set; }
public IEnumerable<ProjectType> ProjectTypes { get; set; }
}
以下是观点:
@using BankruptcyDocketGenerator.ViewModels
@{
ViewBag.Title = "Bankruptcy Docket Generator";
}
@{
ProjectTypesViewModel projectTypes = (ProjectTypesViewModel)ViewBag.ProjectTypes;
}
@Html.DropDownListFor(x => x.SelectedId, new SelectList(projectTypes.ProjectTypes, "Project", "Name"), "Select one...")
我做错了什么?
谢谢, 杰
答案 0 :(得分:0)
基于以下答案,您似乎需要强烈键入视图才能使用lambda表达式。由于您使用的是@Html.DropDownListFor
,因此您使用的是lambda表达式:
Razor View Engine : An expression tree may not contain a dynamic operation
<强>解决方案:强>
将以下内容添加到视图顶部:
@model BankruptcyDocketGenerator.ViewModels.ProjectTypesViewModel
更新控制器以将ViewModel传递给视图,而不是将其设置为ViewBag:
return View(myProjectTypesVm);