I Have a aps MVC razor project, where the razor pages, show a error in the razor helpers than use a lambda expression,
for example:
@model Person
@Html.TextBoxFor(c=>c.Name)
is marked with red underline, and c.Name does no have intelisense.
But if i use
@Html.TextBox("hello")
is not marked with the red underline.
This does let me compile, and execute, but it's annoying, because of the lack of intelisense in the lambda expressions.
the error that gives is:
the type arguments for method cannot be inferred from the usage
Some things I have tried
to change a little the structure of the call:
@(Html.TextBoxFor(c=>c.Name))
Then only the lambda expression is in red and the error says:
cannot convert lambda expression to type because it is not a delegate type
I have the
<compilation debug="true" targetFramework="4.0">
with the targetFramework of my project, and all the other helpers that not uses lambda don't give this error.
What can it be?
I had this problem just now, and I know that it might not be help at all for you since this reply comes 2 years later, but searching in google this was the first result and I worked out a solution.
Turns out that there was a problem (I don't know why) with the "System.Core" reference. I tried to remove and add that reference again but I got an error when adding it. So I searched a bit more and discover that Microsoft made that reference even if it is not visible on your project so to add it again you need to edit the "*.csproj" yourself. I opened it with VS Code (you can even use Notepad) and then added:
<Reference Include="System.Core" />
I did it alphabetically like every other reference but I don't think that's important, in my case that was after "System.ComponentModel.Composition". Hope that this can help you if it happens to you again and maybe help anyone else that finds this question.