Asp.Net MVC4正在搜索ViewBag对象数组
本文关键字:ViewBag 对象 数组 搜索 Net MVC4 Asp | 更新日期: 2023-09-27 18:24:27
在我的视图中得到了以下代码:
int index = Array.FindIndex(ViewBag.EventTypes, (x) => (x.EventCode == Row.EventCode));
获取此异常:
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
在我看来,我该怎么做?我需要在viewbag中的对象数组中搜索EventCode。或者有其他方法可以做到这一点吗?
数组的定义和设置如下:
// mycorses is a list of events.
EventTypes[] etypes = GetEventTypes(mycourses);
ViewBag.EventTypes = etypes;
这是EventTypes对象定义:
public class EventTypes
{
public string EventCode { get; set; }
public string EventType { get; set; }
}
我认为您只需添加as EventTypes[]
就可以了:
int index = Array.FindIndex(ViewBag.EventTypes as EventTypes[],
(x) => (x.EventCode == Row.EventCode));