1

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.

4

2 に答える 2

2

再コンパイルして(Shift-Ctrl-B)、再試行できるはずです-そこにあります。それ以外の場合は、空白のビューの上部でいつでも自分で宣言できますが、ジェネレーターが行う足場は提供されません。

@model MvcDemo.Models.MovieDB;
于 2012-09-25T15:42:22.180 に答える
0

再コンパイルしましたが、問題は解決しませんでした。同じことを行っていて、まったく同じ問題が発生しました。私にとっての問題は、ビジュアルWeb開発者が私のMoviesデータベースに接続できないことが原因でした。web.config内のconnectionStringの定義を次のように変更する必要がありました。

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

この問題が発生している場合は、Movies.sdfデータベースファイルを指すように「データソース」パスを変更する必要があります。

于 2013-02-22T23:47:11.310 に答える