Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:16:13+00:00 2026-05-30T07:16:13+00:00

I am using EF model first and using viewmodels in MVC, I have problems

  • 0

I am using EF model first and using viewmodels in MVC, I have problems with this error:

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[NKI3.Models.Question]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[NKI3.ViewModels.IndexCreateViewModel]'.

This is my viewmodel:

public class IndexCreateViewModel
{
    public string QuestionText { get; set; }
    public string Sname { get; set; }
    public string Cname {get;set;}
}

This is my Action in my controller:

public ActionResult Index()
{
    var Q = db.Question.Include(a => a.SubjectType).Include(a => a.CoreValue);
    return View(Q.ToList());   
}

Here is my strongly typed view:

@model IEnumerable<NKI3.ViewModels.IndexCreateViewModel>

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            QuestionText
        </th>
        <th>
            Sname
        </th>
        <th>
            Cname
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.QuestionText)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Sname)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Cname)
        </td>

    </tr>
}

</table>

I dont seem to find the solution for this, do I have to return my viewmodel inside the controller action index? Any help is appreciated.

Thanks in advance!

Best Regards!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:16:15+00:00Added an answer on May 30, 2026 at 7:16 am

    See: note down below
    Would it help to return Enumerable?

     return View(Q.AsEnumerable()); 
    

    EDIT: Yeah, I know my first shot was wrong!… did not noticed that your view wants a

    @model IEnumerable<NKI3.ViewModels.IndexCreateViewModel>
    

    I agree with the others about converting to the required return value to the matching type…
    or adjust the expecting type in the view…
    maybe you can take advantage of mapping framworks like automapper (http://automapper.org/) to help you to solve to mapping code between domain objects and viewmodels.

    it’s up to you – No need for further down voting…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using asp.net mvc 2.0(default binding model) and I have this problem. I
I am using custom model binder in ASP.NET MVC 2 that looks like this:
I am using MVC-Viewmodel EF Model First, I am trying to make 2 forms
I am using MVC-Viewmodel and EF model first for my projekt These are my
I am getting started with Entity Framework 4, using model-first development. I am building
I have a simple Poco-Model using abstract classes, and it seems not to work
I'm currently using DataAnnotations to validate my MVC 2 app. However, I've ran into
I currently have a fairly straight forward app, my first attempt at MVVM using
I'm using EF 4 with model-first...I generate the database from the model. How would
I'm using EF 4.1 and code-first in an MVC project, and AutoMapper to map

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.