item.site_url)">@Html.DisplayFor(mod...">

ASP.NET MVC3 Razor Href Error

For some reason this line of code.

<a href="/API/@Html.DisplayFor(modelItem => item.site_url)">@Html.DisplayFor(modelItem => item.api_name)</a> 

throws an error.

 Compiler Error Message: CS1963: An expression tree may not contain a dynamic operation 

Web search did not help, I can not understand what is wrong with the code.

The page is not very typed.

+4
source share
2 answers

As the error says, you cannot use dynamic models with helpers of a type editor with a type.

Instead, you should use typed models. (using @model SomeType )

+6
source

Is your view strongly typed? If not, you need to have a strongly typed representation, since lambdas do not support dynamic elements.

Just add this to the top of your view:

 @model YourModel 
0
source

Source: https://habr.com/ru/post/1386887/


All Articles