Search code examples
asp.net-mvcasp.net-mvc-3scaffolding

creating controller doesn't work


I'm learning asp.net mvc3 from w3schools and following that tutorial.http://w3schools.com/aspnet/mvc_models.asp In the section "ASP.NET MVC Models" I have created the model like this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MvcDemo.Models
{
    public class MovieDB
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Director { get; set; }
        public DateTime Date { get; set; }
    }

    public class MovieDBContext : DbContext
    {
        public DbSet<MovieDB> Movies { get; set; } 
    }
}

Then I was going to add a controller according to the instructions.

  • In the Solution Explorer, right-click the Controllers folder, and select Add and Controller Set controller name to MoviesController
  • Select template: Controller with read/write actions and views, using Entity Framework
  • Select model class: MovieDB (McvDemo.Models)
  • Select data context class: MovieDBContext (McvDemo.Models)*
  • Select views Razor (CSHTML)
  • Click Add

But the problem I have is that the drop down list doesn't show MovieDB (McvDemo.Models) in Model Class and Data Context Class to be selected. Can anyone please help me? Thanks.


Solution

  • You should just be able to recompile (Shift-Ctrl-B) and then try it again - it will be there. Otherwise you can always just declare it yourself at the top of a blank view, but that will not provide the scaffolding that the generator does:

    @model MvcDemo.Models.MovieDB;