LINQ not working in Views. Any ideas how to fix this?
System.Linq doesn't seem to be referenced in any of my v开发者_StackOverflow中文版iews, even though it is. Any LINQ code in any of my views appears as it does in this image, and Intellisense doesn't work
However, the LINQ code does work in all of my .cs files, and the code in the views still works when I run the solution.
when I hit Alt+Enter I get a little message "Failed to import method".
Make sure you have Linq referenced in Pages section of web.config
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
...........
<add namespace="System.Linq" />
................
</namespaces>
</pages>
I would check these in the following order -
- System.Linq reference in the project references.
- Target Framework should be .NET 3.5 or Above
- Is the file ReadOnly ?
Ensure the DLL does not have "copy local" set to False - worked for me.
精彩评论