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 3871654
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:50:40+00:00 2026-05-19T21:50:40+00:00

I am following along with the music store example to try learn ASP.NET MVC.

  • 0

I am following along with the music store example to try learn ASP.NET MVC. I’m creating a cookbook application.

I have created my viewmodel that looks like this:

namespace CookMe_MVC.ViewModels
{
    public class CookMeIndexViewModel
    {
        public int NumberOfReceipes { get; set; }
        public List<string> ReceipeName { get; set; }
    }
}

my controller looks like this

public ActionResult Index()
    {
        var meals= new List<string> { "Dinner 1", "Dinner 2", "3rd not sure" };
       //create the view model
        var viewModel = new CookMeIndexViewModel
        {
            NumberOfReceipes = meals.Count(),
            ReceipeName = meals
        };
        return View(viewModel);
    }

Finally my view looks like this

 @model IEnumerable<CookMe_MVC.ViewModels.CookMeIndexViewModel>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

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

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
        </td>
        <td>
            @item.ReceipeName
        </td>
    </tr>
}

</table>

I get this error.

The model item passed into the dictionary is of type CookMeIndexViewModel, but this dictionary requires a model item of type IEnumerable<CookMeIndexViewModel>.

I have followed the example. I can’t see what I am doing wrong. Should I be returning my viewmodel as a generic list?

  • 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-19T21:50:41+00:00Added an answer on May 19, 2026 at 9:50 pm

    In your view you are using @model IEnumerable<CookMe_MVC.ViewModels.CookMeIndexViewModel> which indicates that the model expected by the View is of type IEnumerable of CookMeIndexViewModel.

    However in the controller you are passing an object of type CookMeIndexViewModel as a model return View(viewModel); hence the error.

    Either change the view to have @model CookMe_MVC.ViewModels.CookMeIndexViewModel

    or pass a IEnumerable of CookMeIndexViewModel as model to the view in controller as given below:

    public ActionResult Index()
    {
            var meals= new List<string> { "Dinner 1", "Dinner 2", "3rd not sure" };
         //create the view model
            var viewModel = new CookMeIndexViewModel
            {
                    NumberOfReceipes = meals.Count(),
                    ReceipeName = meals
            };
            List<CookMeIndexViewModel> viewModelList = new List<CookMeIndexViewModel>();
            viewModelList.Add(viewModel);
            return View(viewModelList);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following along the ASP.Net MVC3 application Music Store and I've noticed this. Here
I am currently following along with http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-model to get a grasp of MVC 4.
I have been following along with the Aaron Skonnard videos on creating a WCF
I'm just starting out learning ASP.NET MVC 3. I've been going through the Music
I have been following along this example to load .obj Model using three.js. Since
I'm following along with the RavenDB on Tekpub talking about using it with ASP.NET
I have an HTML along the following lines: <div class=hiddenClass> // this implies display:none
I've been following along with this excellent asio tutorial , but have got confused
I'm following along with 'Why's Poignant Guide to Ruby' in order to learn Ruby
I have been following along with the book Practical Django Projects. Very nice book,

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.