我想在我的网络 API GET 和 POST 方法中将对象作为参数传递。我的代码是,
[HttpGet]
[Route("mytest/list/{model}")]
public IHttpActionResult GetAllTypes(TestModel model)
{
//my logic here
}
当我调用它时,控制台收到一条错误消息:未找到。我试过了,
[HttpGet]
[Route("mytest/list/{model?}")]
public IHttpActionResult GetAllTypes(TestModel model)
{
//my logic here
}
但是,参数对象得到空值。
最佳答案
不要通过 GET 传递对象。
POST 对象并使用 [HttpPost]
属性。
如果你真的想通过 GET 来做,你可以使用这个:
[HttpGet]
public IHttpActionResult GetAllTypes([FromUri] TestModel model)
关于asp.net-mvc - 如何在 Web Api 中将对象作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43538171/