9
我想寫用以下原型的API:使用可選的複雜類型動作參數爲POST的Web API
[HttpPost]
public ApplicationStatus appLogIn(string id, UserCredentials userCredentials = null)
但是,當我對這個API的請求,帶或不帶userCredentials
,我得到響應代碼以下錯誤作爲500
{
"Message": "An error has occurred.",
"ExceptionMessage": "Optional parameter 'userCredentials' is not supported by 'FormatterParameterBinding'.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": null
}
如果我不作userCredentials可選,一切工作正常。所述userCredential定義如下:
public class UserCredentials
{
public string password { get; set; }
public string username { get; set; }
}
看起來像這樣有答案:http://stackoverflow.com/questions/17236527/asp-net-web-api-formatter-parameter-binding-exception –