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

  • SEARCH
  • Home
  • 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 8447549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:12:19+00:00 2026-06-10T10:12:19+00:00

I am trying to get into the mvc technology and I am reading a

  • 0

I am trying to get into the mvc technology and I am reading a book ‘pro asp.net mvc 3 framework’ from apress.
I got stuck at one place and I don’t know how to solve it now, since this is so much different then ordinary web forms.
Here is the error I am getting: The model item passed into the dictionary is of type ‘System.Data.Entity.Infrastructure.DbQuery`1[SportsStore.Domain.Entities.Product]’, but this dictionary requires a model item of type ‘SportsStore.WebUI.Models.ProductsListViewModel’.

I don’t know which code exactly I need to paste but this is what I have:

View:

@model SportsStore.WebUI.Models.ProductsListViewModel           
@{
    ViewBag.Title = "Products";
}

<h2>List</h2>

@foreach (var s in Model.Products)
{
    <div class="item">
    <h3>@s.Name</h3>
    @s.Description
    <h4>@s.Price.ToString("c")</h4>
    </div>    
}

<div class="pager">
@Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new { page = x }));
</div>

product controller:

namespace SportsStore.WebUI.Controllers
{
    public class ProductController : Controller
    {
        public int PageSize = 4;
        private IProductsRepository repository;

        public ProductController(IProductsRepository productsRepository)
        {
            repository = productsRepository;
        }

        public ViewResult List(int page=1)
        {
            ProductsListViewModel viewModel = new ProductsListViewModel
            {
                Products = repository.Products
                .OrderBy(p => p.ProductID)
                .Skip((page - 1) * PageSize)
                .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    ItemsPerPage = PageSize,
                    TotalItems = repository.Products.Count()
                }
            };
            return View(repository.Products.OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize));
        }       
    }    
}

Please let me know if you need more info.
Thanks, Laziale

  • 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-06-10T10:12:20+00:00Added an answer on June 10, 2026 at 10:12 am

    Change this:

    return View(repository.Products.OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize));
    

    to this:

    return View(viewModel);
    

    Your page is expecting a model of type SportsStore.WebUI.Models.ProductsListViewModel. You were creating an instance of this view model from your data repository, but didn’t do anything with it once it was created. MVC was getting confused because the model that you sent to the view was different than it was expecting. I just change the return to use the viewModel that you had already created in the lines before the return.

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

Sidebar

Related Questions

I'm trying to get into MVC and currently reading the wrox professional ASP.NET MVC
I'm trying to get my company to move to ASP.NET MVC and away from
I'm trying to get my build number into the web.config of an ASP.Net MVC
I am working on an ASP.NET MVC project and I am trying to get
I'm trying to build a global menu into my ASP.NET MVC site.master, and I
I'm trying to get the MVCToolkit working with an ASP.NET MVC Beta application and
I'm just trying to get back into .NET MVC with the new release and
I am trying to get into android development, after some reading i have settled
I've got a windows service compiled as AnyCPU. I'm trying to get it into
Trying my way on a little bit of JSON here in my asp.net mvc

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.