У меня есть общая модальная структура, которая находится на моем макете.
<div class = "modal fade" id = "m_modal_general">
<div class = "modal-dialog modal-lg" role = "document">
<div id = "generalModal" class = "modal-content"></div>
</div>
</div>
На странице индекса моего клиента я могу легко вызвать модальное содержимое как частичное представление из контроллера.
$(function () {
$("#newCustomer").click(function () {
var $buttonClicked = $(this);
$.ajax({
type: "GET",
url: "/Customer/Customer_Add",
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (data) {
$('#generalModal').html(data);
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
});
public IActionResult Customer_Add()
{
return PartialView("~/Views/Customer/AddCustomerPartial.cshtml");
}
Теперь я хочу получить еще один частичный результат, когда я щелкнул строку таблицы данных, но результат вызова ajax дает ошибку. Что не так в моем коде?
function OperationDetail() {
var table = $('#tbloperations').DataTable();
$('#tbloperations tbody').on('click', 'tr', function () {
var data = table.row(this).data();
$.ajax({
url: '/Customer/CustomerOperationDetail_Read',
type: 'GET',
dataType: 'json',
data: { customerOperationId: data.Id },
success: function (result) {
$('#generalModal').html(data);
},
error: function (error) {
alert("Dynamic content load failed.");
}
});
});
}
public async Task<ActionResult> CustomerOperationDetail_Read(int customerOperationId){
var result = await operationsBusiness.GetCustomerOperationDetails(new GetCustomerOperationDetailsCommand {
OperationId = customerOperationId
});
CustomerOperationDetailsVm vm = new CustomerOperationDetailsVm();
vm.CustomerOperationDetails = result.Result;
return PartialView("~/Views/Customer/OperationDetailsPartial.cshtml",vm);
}

у вас ошибка в этой функции.
попробуйте это решение:
function OperationDetail() {
var table = $('#tbloperations').DataTable();
$('#tbloperations tbody').on('click', 'tr', function () {
var data = table.row(this).data();
$.ajax({
url: '/Customer/CustomerOperationDetail_Read',
type: 'GET',
dataType: 'json',
data: { customerOperationId: data.Id },
success: function (result) {
$('#generalModal').html(result);
},
error: function (error) {
alert("Dynamic content load failed.");
}
});
});
}
ОБНОВИТЬ
попробуйте Попробуйте поставить этот код:
$(function () {
$("#newCustomer").click(function () {
var $buttonClicked = $(this);
$.ajax({
type: "GET",
url: "/Customer/Customer_Add",
success: function (data) {
$('#generalModal').html(data);
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
});
public IActionResult Customer_Add()
{
return PartialView("~/Views/Customer/AddCustomerPartial.cshtml");
}
другая функция:
function OperationDetail() {
var table = $('#tbloperations').DataTable();
$('#tbloperations tbody').on('click', 'tr', function () {
var data = table.row(this).data();
$.ajax({
url: '/Customer/CustomerOperationDetail_Read',
type: 'GET',
data: { customerOperationId : data.Id },
success: function (result) {
$('#generalModal').html(result);
},
error: function (error) {
alert("Dynamic content load failed.");
}
});
});
}
public async Task<ActionResult> CustomerOperationDetail_Read(int customerOperationId){
var result = await operationsBusiness.GetCustomerOperationDetails(new GetCustomerOperationDetailsCommand {
OperationId = customerOperationId
});
CustomerOperationDetailsVm vm = new CustomerOperationDetailsVm();
vm.CustomerOperationDetails = result.Result;
return PartialView("~/Views/Customer/OperationDetailsPartial.cshtml",vm);
}
я видел, что .html (данные) должны быть html (результат), но результат все равно выдает функцию ошибки. Спасибо
я не мог найти сообщение об ошибке в функции (ошибка).
Попробуйте добавить конечную точку к вашему контроллеру, чтобы иметь возможность обнаруживать исключение
Я добавил, но не смог найти сообщение об ошибке, извините.
Я обновил свой ответ, надеюсь, что этот ответ поможет вам сейчас
я изменил тип данных: «json» на тип данных: «html», и это сработало.
Вы можете изменить его на html или удалить.
Когда я изменил тип данных json на html. Это сработало.
function OperationDetail(customerOperationId) {
if (customerOperationId > 0) {
$.ajax({
url: '/Customer/CustomerOperationDetail_Read',
type: 'GET',
dataType: 'html',
data: { customerOperationId: customerOperationId },
success: function (result) {
$('#generalModal').html(result);
},
error: function (xhr, textStatus, errorThrown) {
alert(xhr.responseText);
}
});
}
}
Какую ошибку вы получаете?