找到了与请求匹配的多个操作:System.Net.Http.HttpResponseMessage

时间:2015-09-26 05:19:57

标签: asp.net asp.net-web-api url-routing asp.net-web-api-routing

我的路线:

// Web API routes
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

// Controllers with Actions
// To handle routes like `/api/VTRouting/route`
config.Routes.MapHttpRoute(
   name: "ControllerAndAction",
   routeTemplate: "api/{controller}/{action}/{id}",
   defaults: new { id = RouteParameter.Optional ,extension = RouteParameter.Optional }
);

我的API是:

[System.Web.Mvc.HttpPost]
[System.Web.Mvc.ActionName("san")]
public HttpResponseMessage san([FromBody]Login value)
{
   var result = db.SSI_Member_Registation.Where(c => c.InqID == value.userid && c.BirthDt == value.Password).FirstOrDefault();
   return Request.CreateResponse(HttpStatusCode.OK, result);
}

//// POST api/values
[System.Web.Mvc.HttpPost]
[System.Web.Mvc.ActionName("san1")]
public void Post([FromBody]string value)
{
}

我将参数作为Json传递并排成行 [![在此处输入图像说明] [1]] [1]

我做错了什么?

1 个答案:

答案 0 :(得分:3)

更改路线的顺序:

WHERE (SM.CourseID=@CourseID OR @CourseID=0)
      AND
      (SM.ClassID=@ClassID OR @ClassID=0)
      AND
      (SM.ClassSectionID=@ClassSectionID OR @ClassSectionID=0)
      AND
      SD.StudentID<>SS.StudentID

如果您先注册默认值,它将覆盖其余部分。