我的控制器中有三个 POST Action 方法
PostProjectData([FromBody] MyObject 对象)
PostCustData([FromBody] MyObject 对象)
PostBookData([FromBody] MyObject 对象)
那么 Web API 将如何识别每个方法???
提前致谢
我的控制器中有三个 POST Action 方法
PostProjectData([FromBody] MyObject 对象)
PostCustData([FromBody] MyObject 对象)
PostBookData([FromBody] MyObject 对象)
那么 Web API 将如何识别每个方法???
提前致谢
你认为这在 Web API 平台上是一个好的设计吗?
我认为拥有会更好
ProjectController 将负责 PostProjectData([FromBody] MyObject 对象)
CustController 将负责 PostCustData([FromBody] MyObject 对象)
BookController 将负责 PostBookData([FromBody] MyObject 对象)
如果你真的想用这种方式,你可以通过以下方式设置路由。
config.Routes.MapHttpRoute(
string.Empty,
"yourroute1",
new { controller = "yourcontroller", action = "PostProjectData" },
new { httpMethod = new HttpMethodConstraint(HttpMethod.Get.Post) }
);
config.Routes.MapHttpRoute(
string.Empty,
"yourroute2",
new { controller = "yourcontroller", action = "PostCustData" },
new { httpMethod = new HttpMethodConstraint(HttpMethod.Get.Post) }
);
config.Routes.MapHttpRoute(
string.Empty,
"yourroute3",
new { controller = "yourcontroller", action = "PostBookData" },
new { httpMethod = new HttpMethodConstraint(HttpMethod.Get.Post) }
);
但我认为你应该重新设计控制器,因为资源是 Project、Cust 和 Book。他们应该有自己的控制器。那正确吗?