当我将json响应发送回我的api时,模型报告为null并且不会更新。我已将Content-Type设置为application / json
请求:
[{" SurveyID":" 55"," QuestionID":" 4","回复": 6},{" SurveyID":" 55"," QuestionID":" 12","回复":& #34; 1"}]
控制器:
public HttpResponseMessage Post([FromUri] Response response)
{
try
{
if (ModelState.IsValid)
{
using (NPSEntities entities = new NPSEntities())
{
entities.Responses.Add(response);
entities.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK);
}
}
else
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, "Invalid Model");
}
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
throw;
}
}
模型:
public partial class Response
{
public int ResponseID { get; set; }
public string SurveyID { get; set; }
public string QuestionID { get; set; }
public string Responses { get; set; }
public Nullable<System.DateTime> ModifyDate { get; set; }
}