Dustin E
Dustin E

Reputation: 368

"Unknown element" in Strongly typed View with Generic Model

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

Answers (4)

Bruce
Bruce

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

kbokach
kbokach

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

StriplingWarrior
StriplingWarrior

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:

  1. Make sure any line mentioning System.Web.Mvc has the version number changed to 5.0.0.0.
  2. Make sure any line mentioning System.Web.WebPages.Razor has the version number changed to 3.0.0.0.

Upvotes: 4

Anthony Chu
Anthony Chu

Reputation: 37530

Use a lower case m...

@model List<string>

Upvotes: 1

Related Questions