我有一个控制器 ( RequestsController
) 有几个动作(都采用一个参数)
例如:
public List<Models.AcceptRequests> GetAllAcceptRequests(int passedId)
public List<Models.Requests> GetAllRequests(int passedId)
public List<Models.CancelRequests> GetAllCancelRequests(int passedId)
我将这些操作中的每一个调用jQuery
ajax
如下:
var s = { passedId: 0, } $.ajax({ url: "../api/Requests/GetAllAcceptRequests", type: "GET", dataType: 'json', data: JSON.stringify(s), contentType: "application/json; charset=utf-8", success: function (response) { vm.Requests(ko.utils.unwrapObservable(ko.mapping.fromJS(response))); } });
我收到以下错误:
Multiple actions were found that match the request: System.Collections.Generic.List1 [TCMSWeb.Models.Requests] GetAllRequests(Int32)
据我了解,controller
action
无论参数与其他操作是否冲突,您都可以调用 a 。不是这样吗?
如何controller
action
在不必为每个参数指定唯一数量的参数的情况下调用每个参数?
编辑:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}