2014-01-22 42 views
0

描述:在當前web請求的執行過程中發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。MVC 4錯誤(如何可以糾正在「/」應用服務器錯誤?)

異常詳細信息:

System.Reflection.AmbiguousMatchException: The current request for action 'index' on controller type 'CategoryController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type Onclickmuseum.Controllers.CategoryController System.Web.Mvc.ActionResult Index(Onclickmuseum.Models.CategoryModel) on type Onclickmuseum.Controllers.CategoryController

源錯誤:

在當前web請求的執行過程中生成未處理的異常。關於異常的來源和位置的信息可以使用下面的異常堆棧跟蹤來標識。

堆棧跟蹤:

[AmbiguousMatchException: The current request for action 'index' on controller type 'CategoryController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type Onclickmuseum.Controllers.CategoryController System.Web.Mvc.ActionResult Index(Onclickmuseum.Models.CategoryModel) on type Onclickmuseum.Controllers.CategoryController]
System.Web.Mvc.Async.AsyncActionMethodSelector.FindAction(ControllerContext controllerContext, String actionName) +276
System.Web.Mvc.Async.ReflectedAsyncControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName) +181
System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName) +52
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +295
System.Web.Mvc.<>c_DisplayClass1d.b_17(AsyncCallback asyncCallback, Object asyncState) +83
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +161

+0

這可能是http的副本://計算器您可以通過消除不確定性.COM /問題/ 732205 /如何-可以-I-避免-ambiguousmatchexception兩間控制器,行動 –

回答

0

這意味着,MVC發現了兩個動作方法具有相同的名稱,是困惑。

添加一個HTTP方法屬性:

[HttpGet] // This method will be called only on GET http requests 
public ActionResult Index() { ... } 

[HttpPost] // This method will be called only on POST http requests 
public ActionResult Index(int id) { ... } 

指定動作名稱:

// This method will be called for /ControllerName/Index requests 
public ActionResult Index() { ... } 

[ActionName("Index2")] // This method will be called for /ControllerName/Index2 requests 
public ActionResult Index(int id) { ... } 
1

你所得到的錯誤告訴ASP.NET MVC已經發現了兩個名稱相同的動作,不能選擇使用哪一種。