我正在學習使用ASP.Net MVC創建NerdDinner的教程。但是,我正在使用Visual Studio 2010 Ultimate版本,並且只有MVC2可供選擇。關於ASP.Net控制器的新手問題MVC
所以我已經按照教程到目前爲止,一切都真正點擊,並得到很好的解釋,直到這個小小的麻煩。
該指南要求我創建一個Controller文件的新方法,像這樣:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace NerdDinner.Controllers
{
public class DinnersController : Controller
{
public void Index(){
Response.Write("<h1>Coming Soon: Dinners</h1>");
}
public void Details(int id) {
Response.Write("<h1>Details DinnerID: " + id + "</h1>");
}
}
}
然而,當我創建了控制器文件,Visual Studio中創建的索引方法了,但它看起來大大不同於教程顯示的內容。也許這是使用MVC2做事的新方法?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace NerdDinner.Controllers
{
public class DinnersController : Controller
{
//
// GET: /Dinners/
public ActionResult Index()
{
return View();
}
}
}
我的問題是,我怎麼能重現MVC2方式的細節和索引方法(他們在MVC中)?
這是甚至相關?謝謝!
本書只是爲了演示如何在不設置視圖的情況下工作。稍後教程將告訴您在解釋視圖的概念時,用ActionResult返回類型替換void。是的,這有點奇怪。 – 2010-06-11 01:48:30
確切地說,我覺得這個教程有點玷污了這個教程,但是他們後來真的會教你以前你在做什麼(這個問題存在的原因)是明顯錯誤的。 – 2010-06-11 02:00:49