问题描述
我正在尝试在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 (将#修改为@)