Razor View throwing “The name 'model' does

2019-01-06 10:55发布

After significant refactoring in my MVC 4 application, and Razor shows this error while debugging Views:

The name 'model' does not exist in the current context.

This is the offending line of code:

@model ICollection<DataSourceByActive>

I know that the usage of @model is correct.

Why is this happening? How can I fix it?

20条回答
家丑人穷心不美
2楼-- · 2019-01-06 11:42

For me, the issue was a conflicting .NET version in one of the libraries that I recently imported. The library I imported was compiled for 4.5.2 and the ASP.NET MVC site I imported it into targeted 4.5. After recompiling said lib for 4.5 the website would comppile.

Also, there were no compilation errors, but the issue was being reported as a "warning". So be sure to read all warnings if there are any.

查看更多
beautiful°
3楼-- · 2019-01-06 11:42

You are likely to use in the code a variable named model.

查看更多
登录 后发表回答