Asp.net-mvc – An expression tree may not contain a dynamic operation – mvc

asp.net-mvcmodel

I have this in my code:

@model Tuple<IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>>

@(Html.Telerik().Grid(Model.Item3)
    .Name("Grid")
    .DataKeys(keys => keys.Add(c => c.Id))
)

And I get the error: An expression tree may not contain a dynamic operation.

Here is the controller code:

FirstClass firstC= new FirstClass ();
IEnumerable<dynamic> first= firstC.All();

SecondClass secondC= new SecondClass ();
IEnumerable<dynamic> second= secondC.All();

ThirdClass thirdc = new ThirdClass ();
IEnumerable<dynamic> third= thirdc .All();

Tuple<IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>> result =
            new Tuple<IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>>(firstC, secondC, thirdc );
return View(result);

How to resolve this?

Best Answer

Expressions cannot be used with dynamic types. You will have to use strongly typed view models:

@model Tuple<IEnumerable<VM1>, IEnumerable<VM2>, IEnumerable<VM3>>
Related Topic