描述:在执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
例外详细信息:
System.Reflection.AmbiguousMatchException:当前请求 控制器类型'CategoryController'上的动作'索引'是不明确的 以下操作方法之间:System.Web.Mvc.ActionResult Onclickmuseum.Controllers.CategoryController类型的索引() System.Web.Mvc.ActionResult索引(Onclickmuseum.Models.CategoryModel) 在类型Onclickmuseum.Controllers.CategoryController
来源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
堆栈追踪:
[AmbiguousMatchException:当前的操作请求'index'on 控制器类型'CategoryController'之间是不明确的 以下操作方法:System.Web.Mvc.ActionResult索引()类型 Onclickmuseum.Controllers.CategoryController System.Web.Mvc.ActionResult索引(Onclickmuseum.Models.CategoryModel) 在类型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 州)+295
System.Web.Mvc<> C_ DisplayClass1d.b _17(的AsyncCallback asyncCallback,Object asyncState)+83
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback的 回调,对象状态,Int32超时)+161
答案 0 :(得分:1)
您收到的错误告诉ASP.NET MVC找到了两个具有相同名称的操作,但无法选择使用哪个。
答案 1 :(得分: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) { ... }