如何解决Ajax发布功能不在列表中显示数据
我正在尝试在ASP.Net Core应用程序中创建一个弹出窗口,以使用Ajax创建新客户或编辑现有客户。但是,当我执行发布请求时,数据未显示在客户列表中。我需要刷新页面才能显示此数据,但我不知道出了什么问题。
这是我的Ajax方法:
PostCustomer = form => {
$.ajax({
type: 'POST',url: form.action,data: new FormData(form),contentType: false,processData: false,success: function (res) {
if (res.isValid) {
$('#view-all-customer').html(res.html)
$('#form-modal .modal-body').html('');
$('#form-modal .modal-title').html('');
$('#form-model').modal('hide');
}
else
$('#form-modal .modal-body').html(res.html);
},error: function (err) {
console.log(err)
}
})
return false;
}
这是我在控制器中的功能
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult CreateOrUpdate(Customer customer)
{
if (ModelState.IsValid)
{
//Insert
if (customer.CustomerId == 0)
{
_customerRepository.Create(customer);
}
//Update
else
{
_customerRepository.Update(customer);
}
return Json(new { isValid = true,html = Helper.RenderRazorViewToString(this,"_ViewAllCustomer",List()) });
}
return Json(new { isValid = false,"CreateOrUpdate",customer) });
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。