2011-07-05 6 views
0

私はこのガイドhttp://www.pluralsight-training.net/microsoft/players/PSODPlayer.aspx?author=scott-allen&name=mvc3-building-data-i&mode=live&clip=0&course=aspdotnet-mvc3-intro(パート3コードが最初に来ます)に従おうとしていますが、私はそれをスレーブのように続けました。ASP.net MVC 3が自動的にSQLテーブルを作成していません(Pluralsightに続いて)

MSDNのバージョンをインストールしたので、Visual Studio Ultimateでは、Web開発者ではなく、2010年に彼が使用しているように表現されています。だから私はただ代わりにそれをインストールします。

私はデータベースに現在のWeb要求の

Server Error in '/' Application. 
Value cannot be null. 
Parameter name: key 
Description: An unhandled exception occurred during the 

実行を使用する必要があるサイトにアクセスしようとすると、私はこのエラーを取得します。 エラーについての詳細は のスタックトレースを参照し、 がコード内で発生した場所を確認してください。

Exception Details: System.ArgumentNullException: Value 

nullにすることはできません。 パラメータ名:キー

Source Error: 

Line 15:  
Line 16: 
Line 17: @foreach (var item in Model) 
Line 18: { 
Line 19:  @item.Title 


Source File: c:\Users\Mech0z\Documents\Visual 

メーカー 2010プロジェクト\ FirstWeb \ FirstWeb \ビュー\ \ギャラリー\ Index.cshtml ライン:17

Stack Trace: 

私のコードは次のとおりです。

接続文字列:

私はworkignないwhicih thatsのいくつかの余分なメソッドを持ってい

ピクチャーモデル

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

namespace FirstWeb.Models 
{ 
    public class Picture 
    { 
     public int ID { get; set; } 
     public string Title { get; set; } 
     public string Path { get; set; } 
     public List<Comment> Comments { get; set;} 
     public int ConcertYear { get; set; } 
     public HttpPostedFileBase File { get; set; } 
     public string UploadBy { get; set; } 
    } 
} 

私のコントローラ

namespace FirstWeb.Controllers 
{ 
    public class GalleryController : Controller 
    { 
     GalleryDb _db = new GalleryDb(); 
     // 
     // GET: /Gallery/ 

     public ActionResult Index() 
     { 
      var model = _db.Pictures; 
      return View(model); 
     } 

そして、私のgalleryDB

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

namespace FirstWeb.Models 
{ 
    public class GalleryDb : DbContext 
    { 
     public DbSet<Picture> Pictures { get; set; } 
     public DbSet<Comment> Comments { get; set; } 

     public DbSet<Picture> GetPictures() 
     { 
      return Pictures; 
     } 

     public void AddPicture(Picture model) 
     { 
      Pictures.Add(new Picture 
      { 
       Title = model.Title, 
       Path = model.Path, 
       Comments = new List<Comment>(), 
       ConcertYear = model.ConcertYear 
      }); 
     } 
    } 
} 

はちょうど私がすることなく、一時データを使用したときからのものですSQL

しかし、私は傾けることはできませんDBへのCT彼が道(型付け。\ SQLEXPRESSと名前としてGalleryDbを入力)し、それは私にエラーを与える

しかし、私は任意のポイント

+0

は、Visual Studioのサーバーエクスプローラでデータベースに接続することができますか? web.configで設定した接続文字列は何ですか? web.configファイルのセクション全体を貼り付けることはできますか? –

+0

Kyle Trauberman http://pastebin.com/gJKfz6s7 – Mech0z

+0

\ sqlexpressとGalleryDbを試しても接続できません – Mech0z

答えて

0

のユーザとログインを作成することができますように、データベースが稼働している必要がありますどうやらデータエンティティは、だから私のモデルから、それがうまく働いたことを取り除いた後、このプロパティ

public HttpPostedFileBase File { get; set; }

が好きではありません

関連する問題