- VS2012+ Windows 8
- ASP.NET 4.5
- for Lab1.5
CTRL+F5
CTRL+F5
延續此文範例 Q&A ASP.NET Dynamic Data 實體網站
修改global.asax
加一個authors目錄
客製化,如加上字串
run
Visual Studio 2012 的ASP.NET Dynamic Data 實體網站範本,使用Entity Framework 5.0,因此要啟用Dynamic Data的語法有一點不同:
1.
Add ADO.NET Entity Data Model
修改global.asax,RegisterRoutes方法:
PS:這部分和VS2010最大不同的是DefaultModel.RegisterContext的寫法,需這樣寫
DefaultModel.RegisterContext(() =>
{
return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)new pubsEntities()).ObjectContext;
}, new ContextConfiguration() { ScaffoldAllTables = true });
ex:
執行網站測試
App_Code目錄,Add authors class:
[MetadataType(typeof(AuthorsMetadata))]
[DisplayName("作者")]
public partial class authors
{
private class AuthorsMetadata
{
[DisplayName("姓氏")]
public string au_lname { get; set; }
[DisplayName("名字")]
public string au_fname { get; set; }
}
}
Run
以下說明如何使用Visual Studio 2012 ,ASP.NET MVC 4 行動裝置範本設計第一個jQuery Mobile範例
1.Create Web AP
2.
3.在Models 目錄下加一個Employee Class:
4.Employee Class:
namespace MvcApplication6.Models {
public class Employee {
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}
5.在Controllers目錄下加一個EmployeeController:
6.在EmployeeController使用GET的Create action 建立Create View:
7.修改有標示HttpPost的Create action:
[HttpPost]
public ActionResult Create( Employee model ) {
try {
// TODO: Add insert logic here
return View( "Result" , model );
} catch {
return View();
}
}
8.在上述步驟程式上方,按右鍵,建立Result View
9.按F5執行,URL輸入Employee/Create:
10.執行畫面:
按Create效果
11.在模擬器上效果。