我需要设置一个Web方法来接受我的安卓和iOS客户端应用程序发送的POST参数。这就是我现在拥有的:
[HttpPost]
[Route("api/postcomment")]
public IHttpActionResult PostComment([FromBody]string comment, [FromBody]string email, [FromBody]string actid)
{
string status = CommentClass.PostNewComment(comment, email, actid);
return Ok(status);
}但是,这不起作用,因为我认为该方法不能同时接受多个FromBody参数?如何正确设置此方法,使其接受来自请求主体的3个POST参数?
发布于 2015-07-17 14:25:12
你可以用模型。DefaultModelBinder将将表单中的这些值绑定到您的模型。


public class CommentViewModel
{
public string Comment { get; set; }
public string Email { get; set; }
public string Actid { get; set; }
}
public IHttpActionResult PostComment([FromBody]CommentViewModel model)
{
string status = ...;
return Ok(status);
}发布于 2015-07-17 14:28:32
你能做到的-
PostComment方法更改为只接受该类的一个参数。https://stackoverflow.com/questions/31477108
复制相似问题