1
votes

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.

2
recompile your code Build->BuildSolution then try it, magic!Liam
@Daniel I learned a lot from w3schools back-in-the-day. There aren't a lot of beginner tutorials out there and they do a job.Liam
my 2cents.. mvcmusicstore.codeplex.com great tutorial to learn MVC :)Tony
Thank you Liam, Tony for answering me, It worked. @Tony, sir thanks for the tutorial u sent me. I'll study that. Thanks again for your help.kinotech
Please don't use W3Schools. Ever.Rory McCrossan

2 Answers

2
votes

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;
0
votes

I recompiled but that did not fix the issue for me and yes I am doing the same thing and ran into the same exact issue. The problem for me was caused by visual web developer not being able to connect to my Movies database. I had to change the definition of my connectionString within web.config like this:

<add name="MovieDBContext"connectionString="Data Source=c:\sites\w3schools_demo\MvcDemo2\MvcDemo2\App_Data\Movies.sdf" providerName="System.Data.SqlServerCe.4.0"/>

If you are having this issue you will need to change the "Data Source" path to point to your Movies.sdf database file.