首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >RestSharp JSON参数发布

RestSharp JSON参数发布
EN

Stack Overflow用户
提问于 2011-06-11 07:18:37
回答 7查看 234.5K关注 0票数 154

我试图对我的MVC3API进行一个非常基本的REST调用,而我传入的参数并没有绑定到action方法。

客户端

代码语言:javascript
复制
var request = new RestRequest(Method.POST);

request.Resource = "Api/Score";
request.RequestFormat = DataFormat.Json;

request.AddBody(request.JsonSerializer.Serialize(new { A = "foo", B = "bar" }));

RestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

服务器

代码语言:javascript
复制
public class ScoreInputModel
{
   public string A { get; set; }
   public string B { get; set; }
}

// Api/Score
public JsonResult Score(ScoreInputModel input)
{
   // input.A and input.B are empty when called with RestSharp
}

我是不是漏掉了什么?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6312970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档