在我的项目中,我是通过搜索过滤的,在API端查询的时候可以得到数据,但是在MVC端消费API的时候没有数据。
API控制器,
[HttpGet("ListExpenseByAccountingSearch/{search}")]
public async Task<IActionResult> ListExpenseByAccountingSearch(string search)
{
var values = await _expenseService.itemListExpenseByAccountingSearch(search);
return Ok(values);
}
字符串
MVC控制器,
[HttpGet]
public async Task<IActionResult> ListExpenseByAccountingSearch(string search)
{
var client = _httpClientFactory.CreateClient();
var responseMessage = await client.GetAsync($"https://localhost:7198/api/Expense/ListExpenseByAccountingSearch/{search}");
if (responseMessage.IsSuccessStatusCode)
{
var jsonData = await responseMessage.Content.ReadAsStringAsync();
var values = JsonConvert.DeserializeObject<List<ResultExpenseByAccountingDto>>(jsonData);
return Json(values);
}
return Json(new List<ResultExpenseByAccountingDto>());
}
型
搜索输入,
<input class="form-control form-control-sm" id="txtSearch" type="text" oninput="listExpenseBySearch()" placeholder="Search...">
型
AJAX ,
function listExpenseBySearch() {
var searchText = $("#txtSearch").val();
$.ajax({
type: "GET",
url: "/Management/Accounting/ListExpenseByAccountingSearch/" + searchText,
success: function (value) {
console.log(value);
$("#tableExpense tbody").empty();
var tablerow;
$.each(value, (index, item) => {
tablerow = $("<tr/>");
tablerow.append(`<td><a class="fw-semibold text-primary">#${item.periodID}</a></td>`)
tablerow.append(`<td>${item.createUser}</td>`)
tablerow.append(`<td>${item.periodMonth}</td>`)
tablerow.append(`<td>${item.periodYear}</td>`)
switch (item.paymentStatus) {
case 9999:
tablerow.append(`<td><span class="badge bg-warning-transparent">Bekleniyor</span></td>`)
break;
case 9998:
tablerow.append(`<td><span class="badge bg-warning-transparent">Onay Sürecinde - Yönetici</span></td>`)
break;
case 9997:
tablerow.append(`<td><span class="badge bg-warning-transparent">Onay Sürecinde - Muhasebe</span></td>`)
break;
case 1:
tablerow.append(`<td><span class="badge bg-warning-transparent">Ödeme Bekleniyor</span></td>`)
break;
case 2:
tablerow.append(`<td><span class="badge bg-success-transparent">Ödeme Yapıldı</span></td>`)
break;
case 3:
tablerow.append(`<td><span class="badge bg-dark-transparent">Gecikmiş Ödeme</span></td>`)
break;
case 4:
tablerow.append(`<td><span class="badge bg-danger-transparent">İptal Edilen Ödeme</span></td>`)
break;
}
let formattedAmount = parseFloat(item.totalAmount).toLocaleString('tr-TR', { minimumFractionDigits: 2 });
tablerow.append(`<td>₺${formattedAmount}</td>`)
tablerow.append(`<td><a href="#" class="btn btn-primary-light btn-icon btn-sm"><i class="ri-eye-line"></i></a> <a href="/Management/Accounting/ExpenseSummary/${item.expenseID}" class="btn btn-primary-light btn-icon btn-sm"><i class="ri-send-plane-2-line"></i></a></td>`)
$("#tableExpense").append(tablerow);
})
},
error: function (xhr, status, error) {
console.log(xhr, status, error);
}
});
}
型
我用Postman获取数据,但是在MVC端的表或控制台中没有数据。它也没有返回任何错误。
1条答案
按热度按时间ghhaqwfi1#
这个API没有返回任何东西,因为你没有正确发送它,端点总是得到空字符串,找不到东西
字符串
此键 (?search=) 应该存在于url中