我不知道这是故障还是我犯的错误。但是我用console.log(record)
这就是结果
accountRateId: 6 effectiveEndDate: "2019-09-30T00:00:00" effectiveStartDate: "2019-09-01T00:00:00" rate: 100
我有这段代码来分配变量
let rate = record.rate;
let effectiveStartDate = record.effectiveStartDate;
let effectiveEndDate = record.effectiveEndDate;
console.log(rate);
但是console.log(rate)返回未定义。有人可以帮我吗?
更新: 这是来自api的代码
[Authorize("ADMIN")]
[HttpGet("Update/{id}")]
public IActionResult GetUpdate([FromQuery]QueryPagingParametersForNotes inParameters, int id)
{
List<object> rateList = new List<object>();
var rateListQueryResults = Database.AccountRates.Where(rate => rate.AccountRateId == id);
foreach (var oneRate in rateListQueryResults)
{
rateList.Add(new
{
accountRateId = oneRate.AccountRateId,
rate = oneRate.RatePerHour,
effectiveStartDate = oneRate.EffectiveStartDate,
effectiveEndDate = oneRate.EffectiveEndDate,
});
}
return new JsonResult(rateList);
}
这是javascript中的代码
$.ajax({
method: 'GET',
url: '/API/AccountRates/Update/' + inId
}).done(function (data) {
let record = data;
console.log(record);
let rate = record.rate;
let effectiveStartDate = record.effectiveStartDate;
let effectiveEndDate = record.effectiveEndDate;
console.log(rate);
console.log(effectiveStartDate);
//Populate the respective input controls with the lesson details.
$('#rateInput').val(rate);
$('#startDateInput').val(effectiveStartDate);
$('#endDateInput').val(effectiveEndDate);
})