ASP.NET MVC Newbie: why isn't my model available when creating a strongly-typed view?

Posted by Rax Olgud on Stack Overflow See other posts from Stack Overflow or by Rax Olgud
Published on 2009-08-13T11:55:43Z Indexed on 2010/04/03 7:13 UTC
Read the original article Hit count: 300

I'm starting with ASP.NET MVC, and working with NerdDinner as reference. I did the following:

  1. Created a new project
  2. Added a couple of tables
  3. Created LINQ to SQL for them
  4. Created a new controller

My Models directory now contains MyModel.dbml, under which I have MyModel.designer.cs, that contains classes for models relating to both of my tables (let's call them Categories and Products).

Now, under my new controller, I would like to create a strongly typed view. So for example I have the following code in my controller (for my application I must work by name, and the "Name" field is unique):

    public ActionResult Details(string name)
    {
        MyModelDataContext db = new MyModelDataContext();
        Product user = db.Products.Single(t => t.Name == name);
        return View(user);
    }

I would like to create a strongly-typed view. So I right-click the line "return View(user)", and choose "Add View...". I click "Create a strongly-typed view". When I click the dropdown of "View data class", I don't see my models, but only:

  1. MyProject.Controllers.AccountMembershipService
  2. MyProject.Controllers.FormsAuthenticationService

What am I missing?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about views