4
我從ControllerApi繼承像這樣(MVC 4)控制器的.NET Web API後返回行動JSON空
public HttpResponseMessage<lightUserInfo> Post(LogOnModel model)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
MembershipUser user = Membership.GetUser(model.UserName);
var userinfo = new lightUserInfo(user);
return new HttpResponseMessage<lightUserInfo>(userinfo);
}
}
}
我能看到物體用戶信息填充罰款,這將返回200 OK瀏覽器......但內容僅僅是空的JSON {}
這裏是客戶端AJAX中的CoffeeScript
$.ajax
url: Meshable.rooturl + "/api/authentication"
data: JSON.stringify authenticationDetails
dataType: "json"
type: "POST"
contentType: 'application/json; charset=utf-8'
error: (e) ->
success: (data) ->
#data comes in as empty {}
類如何'lightUserInfo'定義? – carlosfigueira
ModelState無效? – Cybermaxs
你爲什麼使用HttpResponseMessage?你還在測試? –