我有一個抽象類定義的虛擬函數:重寫虛方法,但有一個新的簽名:所以自定義模型粘合劑可用於
public abstract class ContentController
{
public virtual ActionResult Index();
}
我已經得到了從派生的類上述基類:
public class CartController : ContentController
我需要CartController能夠綁定購物車與自定義模型聯編程序的索引方法。東西通常是這樣的:
public ActionResult Index(Cart cart)
如果我只是把指數(車)函數到CartController類,我得到這個錯誤:
The current request for action 'Index' on controller type 'CartController' is ambiguous between the following action methods:
ActionResult Index() on type CartController
ActionResult Index(Cart) on type CartController
唯一的解決辦法我已經出來與迄今是重命名我的模型綁定功能,並從被覆蓋的指數方法重定向:
public override ActionResult Index()
{
return RedirectToAction("IndexWithCart");
}
public ActionResult IndexWithCart(Cart cart)
{
return View("Index", cart);
}
這樣的作品,但後來我的網址/車/ IndexWithCart。有沒有辦法做到這一點,仍然只有/ Cart網址,而無需修改基類?
尼克 - 這難道不是那麼需要叫IndexWithCart以及新的看法? (即給定的ActionResult IndexWithCart()的返回值是純粹的查看(cart)) – 2010-12-09 14:16:10
我更新了上面的IndexWithCart方法以及我如何在我的代碼中(返回索引視圖) – 2010-12-09 17:00:26