Skip to content

The model item passed into the dictionary is of type ‘WebApplication.Models.ModelNameViewModel’, but this dictionary requires a model item of type ‘System.Collections.Generic.IEnumerable[WebApplication.Models.ModelName]’.

November 30, 2015

If you receive the following error in ASP.NET MVC, The model item passed into the dictionary is of type ‘WebApplication.Models.SampleModelViewModel’, but this dictionary requires a model item of type ‘System.Collections.Generic.IEnumerable[WebApplication.Models.SampleModelViewModel]’.

The issue here is that onthe Razor HTML page, you must of declared on the top of the page: –

 @model IEnumerable<WebApplication.ViewModels.SampleModelViewModel>


So what you need to do here is remove the IENumerable declaration to display only: –

 @model WebApplication.ViewModels.SampleModelViewModel

It is a fairly common thing that could happen, when the view page is expecting something which is  different to what the output of the controller is returning in terms of the data type containing the View Model. You need to make sure they are the same!

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: