我正在学习使用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