我有一个包含信息列表的页面,我可以使用一系列字段和 Ajax 来搜索这些信息。我可以通过将其加载为部分视图来重新加载页面上的信息。但是,重新加载页面后,没有 jQuery 代码起作用。可能是什么问题?
C# 代码:
public async Task<IActionResult> InvoiceSearch(string CurrentPage, string createDate, int? id,
int? remoteFactorNumber, string deliverToPhoneNumber, int? statusInvoice)
{
try
{
var branchId = 0;
if (!User.IsInRole(ConstantRoles.Admin))
{
branchId = User.Identity.GetBranchId();
}
var invoiceParams = new BranchInvoicesResourceParameters
{
PageNumber = !string.IsNullOrEmpty(CurrentPage) ? Convert.ToInt32(CurrentPage) : 1,
CreateDateTime = createDate?.ToEnglishNumbers() ?? null,
InvoiceId = id,
RemoteFactorId = remoteFactorNumber,
StatusInvoice = statusInvoice == null ? null : (StatusInvoice)statusInvoice,
DeliverToPhoneNumber = deliverToPhoneNumber?.ToEnglishNumbers() ?? null,
BranchId = branchId,
};
var branchInvoice = await _invoiceService.GetBranchInvoices(invoiceParams);
return PartialView("_BranchInvoiceList", branchInvoice.Data);
}
catch(Exception ex)
{
}
}
Ajax 调用:
function getSearchInvoice(page) {
var createDate = $('#searchCreateDate').val();
var id = $('#searchId').val();
var remoteFactorNumber = $('#searchRemoteFactorNumber').val();
var deliverToPhoneNumber = $('#searchDeliverToPhoneNumber').val();
var statusInvoice = $('#searchStatusInvoice').val();
var invoice = new Object();
invoice.createDate = createDate;
invoice.id = id;
invoice.remoteFactorNumber = remoteFactorNumber;
invoice.deliverToPhoneNumber = deliverToPhoneNumber;
invoice.statusInvoice = statusInvoice;
$.ajax({
type: "Get",
url: "@Url.Action("InvoiceSearch", "Home")",
headers: {
"RequestVerificationToken": requestVerificationToken
},
data: {
CurrentPage: page,
createDate: createDate,
id: id,
remoteFactorNumber: remoteFactorNumber,
deliverToPhoneNumber: deliverToPhoneNumber,
statusInvoice: statusInvoice
},
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (response) {
},
error: function (xhr, ajaxOptions, thrownError) {
});
};
如果我刷新页面,没有问题,但是当我再次通过 Ajax 检索部分视图时,没有 jQuery 代码起作用。
将所有查询代码放入
$(document).ready(function() {
// your code here
});