Reputation: 368
I am having trouble defining generic models in razor views. Whenever I use a generic model, I get the following warning:
Unknown element 'string' or element cannot be placed here.
Example:
@model List<string>
While this doesn't cause any major errors, it's still very annoying. Is there a way to define a generic in a razor view that doesn't cause this warning?
Environment:
VS 2013
ASP.NET MVC v5.1.2
Razor 3.1.1
Upvotes: 4
Views: 3004
Reputation: 21
Had the same issue and it was an issue caused by an incomplete upgrade from MVC 4 to 5. The suggestions from StriplingWarrior helped but also required the following change to the root web.config:
<add key="webpages:Version" value="3.0.0.0" />
(from version 2.0.0.0)
And a restarting of Visual Studio. Adding those two steps finally fixed the issue.
Upvotes: 2
Reputation: 51
I had the same issue while using a generic type and the versions in the web.config were correct. I had to wrap it in the code block to make the warning disappear.
@{
@model List<MyModelType>
}
Upvotes: 3
Reputation: 156624
I was having the same problem, and it turns out that when I upgraded to the latest version of MVC, not all of my config elements were updated correctly. Changing Web.config in the following ways fixed this for me:
System.Web.Mvc
has the version number changed to 5.0.0.0
.System.Web.WebPages.Razor
has the version number changed to 3.0.0.0
.Upvotes: 4