views:

80

answers:

1

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?

+3  A: 

Recompile your project, the just added model classes do not appear in the list until you've recompiled.

Developer Art
+1 Worked like a charm. Keep it simple stupid :)
Roee Adler
Sometimes errors on the page will cause your intellisense to bomb out in a view. Recompile and run (so asp.net compiles your page) sometimes shows where you've screwed up.
Will