我有一个API方法可将数据插入数据库,但是每当我尝试用邮递员对其进行测试时,它都会返回错误的请求,这是我的代码
private Utilities uti = new Utilities();
private readonly ApplicationDBContext db;
public AppraisalController(ApplicationDBContext context)
{
db = context;
}
//INSERT API FOR AppraisalIdentity table
[AllowAnonymous]
[Route("api/appraiseinsert")]
[HttpPost]
public IActionResult Create([FromBody] AppraisalIdentity cre)
{
if (cre == null)
{
return BadRequest();
}
using (var transaction = db.Database.BeginTransaction())
{
try
{
#region Appraisal Insert
var apprais = new AppraisalIdentity
{
AppraisalName = cre.AppraisalName,
IsCurrent = cre.IsCurrent,
CompanyID = cre.CompanyID
};
db.AppraisalIdentity.Add(apprais);
db.SaveChanges();
#endregion
}
catch (Exception ex)
{
transaction.Rollback();
return Json(new
{
statusCode = ex.Message
});
}
}
return Json(new
{
statusCode = "Success"
});
}
每当我尝试在邮递员身上进行测试时 首先...。如果我尝试使用json,它将返回“坏字符串”。我不知道故障是由于api还是我的插入值的json方法引起的。...json格式正在使用
{
“AppraisalName” : “Appraisal Name”,
“IsCurrent”: 1,
“CompanyID”: 2
}
答案 0 :(得分:4)
“”的符号是什么?我认为Json字符串的正确是:
{
"AppraisalName" : "Harish",
"IsCurrent": 1,
"CompanyID": 2
}