如何在隐藏时从 bootstrap 模态中删除数据

How to remove data from bootstrap modal while hiding it

我正在研究 MVC。目前我的情况是,当我从 bootstrap 模式弹出窗口中保存数据时,它会完美保存。当我第二次打开它时,之前保存的值显示在模式弹出窗口中。 bootstrap中调用的模型在第二次打开时会填充之前的值。

有没有办法在保存数据后模态关闭时清除它。这样当我再次打开时它会加载新数据。

下面是动作方法的代码

    [HttpPost]

    public ActionResult Savenfo(int Id, string comment, byte Status, string Code, string Rev, string Email, string Phone)
    {

        var form = objForm.Get(Id);
        if (form != null)
        {
            if (CurrentUserTicket.Dval!= form.DId)
                return new UnauthorizedActionResult();

            form.Comment = comment;
            form.Status = Status;
            form.Code = Code;
            form.Email= Email;
            form.Phone= Phone;
            form.Rev = Rev;
            objForm.Update(form);

            return new AjaxActionResponse(true, "Information has been saved.");

        }

        return new AjaxActionResponse(false, "The specified Information does not exist.");
    }

推荐使用ViewModel绑定数据查看。 所以你可以在保存数据后使用ModelState.Clear()方法清除模型。

您需要在您的控制器 post 方法中使用它。

[HttpPost]
public ActionResult InsertData(ViewModel model)
{
    ModelState.Clear();
    model = new ViewModel();

    return View(model);
}

您应该清除模态 div html 因为您正在从局部视图重新生成模态。下面是删除模态元素的代码。

$('.modalclass').remove();

你可以试试

  $(".modalClass").html("");