如果我沒有弄錯 - ASP.NET MVC的約定似乎希望我爲控制器視圖執行以下操作。我應該打電話給我的每個MVC視圖Index.aspx?
這就是我創建'產品'目錄的日子,我把'我的'索引'視圖放置在該目錄中。然後我創建一個'ProductsController'並在其上創建一個'Index'方法,它返回一個View。只返回沒有參數的View()會去取'Index.aspx'頁面,因爲它與方法名稱相同。
public class ProductsController : Controller
{
public ActionResult Index()
{
return View(); // looks for Index.aspx in Products directory
}
}
現在這就好了。但我最終會有十億個Index.aspx頁面,而我是其中一個從不關閉任何文件的人,所以我最終會變得瘋狂。
或者我可以創建產品/ Products.aspx和我的控制器更改爲以下:
public class ProductsController : Controller
{
public ActionResult Index() // my default routing goes to Index (from sample project)
{
return View("Products");
}
}
我的理解是如何工作的,以及它的MVC設計模式中完全沒做到這一點。它不是黑客或任何類似的東西。
我的問題(在聽取this PDC視頻之後)是關於customizabiltity的約定在MVC(或任何正確的短語)中受到青睞。
所以我想知道如果我錯過了第三種方式,或者如果人們在Visual Studio中使用50個索引選項卡就好了?
所以你不介意Index.aspx頁面噸? – 2009-01-22 23:42:15