我在我的 web api 项目中将 JSON 复杂对象发送到我的用户控件时遇到问题。我一直收到 404。我有一些控件在工作(任何带有路由 /api/{control}/{action}/{id} 的控件)但没有任何带有路由的控件(/api/{control}/{action}/{user }) 将为我工作。任何帮助将不胜感激。
路由配置
config.Routes.MapHttpRoute(
name: "UserApi",
routeTemplate: "api/{controller}/{action}/{User}");
用户对象
public class User
{
public String UserLoginName { get; set; }
public int UserID { get; set; }
public bool IsDeleted { get; set; }
}
控制器
[HttpPost]
public Models.User AddUser([FromBody]User targetUser)
{
var userDTO = new UserDTO();
var businessUser = userDTO.GetNewBusinessObject(targetUser);
return userDTO.GetNewServiceObject(businessUser.Add());
}
json请求
POST http://localhost:54002/api/user/AddUser HTTP/1.1
User-Agent: Fiddler
Host: localhost:54002
content-length: 69
content-type: application/json;charset=utf-8
"{"UserLoginName": "steve ","UserID":-2147483637,"IsDeleted":false}"