作者coldollsheep (加油加油^^)
看板C_Sharp
標題Re: [問題] 用PHP的方式去寫.net
時間Wed Nov 16 13:36:53 2011
原文吃光 根本標題略為相關 藉此發問
我嘗試了一下asp.net mvc架構
在controller 到view的部分 暫時學得很粗淺 沒問題
但是進行到model的時候
線上教學表示需要在model上按右鍵 建立一個類別
如果名稱Movie為例
會產生一個 movie.cs的檔案
我裡面打的東西完全依照範例所打 內容如下
---
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcApplication3.Models
{
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
}
---
之後 進Web.config
把這一段
---
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
---
改成這樣
---
<connectionStrings>
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
最後教學指示 需再建立一個controller
建置如下
---
Controller name: MoviesController. (This is the default. )
Template: Controller with read/write actions and views, using Entity
Framework.
Model class: Movie (MvcMovie.Models).
Data context class: MovieDBContext (MvcMovie.Models).
Views: Razor (CSHTML). (The default.)
---
但是我卻發現 我的Model class的下拉選單 並沒有 Movie這個類別 但是我明明建好了
很奇怪...
--
最後附上教學網址
http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part5-cs
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.218.112.35
※ 編輯: coldollsheep 來自: 61.218.112.35 (11/16 13:38)
→ kinwind:有先build過嗎?model建好之後,要build一下 11/16 13:43
→ coldollsheep:甚麼是build~~~我死定了................ 11/16 13:51
→ coldollsheep:5-minute-introduction-to-aspnet-mvc 11/16 14:07
→ coldollsheep:上面的影片 在大約4:00的時候也有類似的狀況 11/16 14:07
→ coldollsheep:我跟著做 也是到那邊就卡住 11/16 14:07
→ coldollsheep:因為我類別看到不到他有的東西 但是我看到中間沒甚麼 11/16 14:07
→ coldollsheep:build的動作阿? 難道他是快捷鍵? 11/16 14:08
→ kinwind:中文叫做建置專案,請先build一下,vs才抓得到物件 11/16 14:45
→ coldollsheep:u的 看來要硬著頭皮K原文書了 中文資源挺少的 11/16 14:54
→ coldollsheep:g樓上大大 告知 是在該專案上面 右鍵選擇建置 11/16 14:56