ASP.NET MVC Viewmodel trouble...

Posted by ile on Stack Overflow See other posts from Stack Overflow or by ile
Published on 2010-03-21T20:55:39Z Indexed on 2010/03/21 21:01 UTC
Read the original article Hit count: 253

Filed under:
|
|

I've already started similar topic, but still didn't find final solution... So here I am with new one :) ... I'm developing NerdDinner from scratch and now I came to point where I define DinnerViewModel.
Following these instructions (starting from Listing 5) I came to this:

namespace Nerd.Controllers
{

    // View Model Classes  

    public class DinnerViewModel
    {
        public DinnerViewModel(List<Dinner> dinners)
        {
            this.Dinners = dinners;
        }

        public List<Dinner> Dinners { get; private set; }

    } 

    public class DinnerController : Controller
    {
        private DinnerRepository dinnerRepository = new DinnerRepository();

        ....

        public ActionResult NewDinners()
        {
            // Create list of products  
            var dinners = new List<Dinner>();
            dinners.Add(new Dinner(/*Something to add*/));

            // Return view  
            return View(new DinnerViewModel(dinners));
        }


    }
}

Also, the Dinner table in this new version of NerdDinner is a bit shortened (it contains of DinnerID, Title, EventDate and Description fields).

No matter what I try to add here dinners.Add(new Dinner(/*Something to add*/)); I always get following error

Error 1 'Nerd.Model.Dinner' does not contain a constructor that takes '1' arguments C:\Documents and Settings\ilija\My Documents\Visual Studio 2008\Projects\Nerd\Nerd\Controllers\DinnerController.cs 150 25 Nerd

Because I'm total beginner in C# and generally OOP, I have no idea what to do here... I suppose I need to declare a constructor, but how and where exactly?

Thanks,
Ile

© Stack Overflow or respective owner

Related posts about viewmodel

Related posts about c#