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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...