我正在嘗試對我的MVC 3 API進行非常基本的REST調用,並且我傳入的參數沒有綁定到操作方法。RestSharp JSON參數發佈
客戶
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);
服務器
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
}
我失去了一些東西在這裏?
這樣做了!謝謝約翰! – 2011-06-10 23:41:17
哪一個工作? – 2011-06-11 00:04:54
兩者。然而,第二種方法要快得多。 – 2011-06-11 00:32:35