【发布时间】:2012-11-22 05:27:16
【问题描述】:
我正在尝试在 Web API 中创建一个 RouteConfig,它允许以下模式:
模式:
/api/{controller}
/api/{controller}/{id} (int, optional)
/api/{controller}/{action}
/api/{controller}/{action}/{id} (int, optional)
用例:
/api/profile/ (get all profiles)
/api/profile/13 (get profile number 13)
/api/profile/sendemail/ (send email to all profiles)
/api/profile/sendmail/13 (send email to profile number 13)
我正在尝试以下内容:
routes.MapHttpRoute(
name: "ControllerAndID",
routeTemplate: "api/{controller}/{id}",
defaults: null,
constraints: new { id = @"^\d+$" } // Dekkar heiltölur eingöngu í id parameter
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "Get", id = RouteParameter.Optional }
);
我得到的错误是:
找到多个与请求匹配的操作: \r\nMinarSidur.Models.DataTransfer.UserProfileDTO sendmail(System.String) 关于类型 MinarSidur.Controllers.ProfileController\r\nMinarSidur.Models.DataTransfer.UserProfileDTO 类型 MinarSidur.Controllers.ProfileController 上的 sendpaycheck(System.String)
你能帮我完成这个吗?
【问题讨论】:
标签: asp.net-mvc-4 routes asp.net-web-api