如何在隐藏它时从引导模式中删除数据

时间:2015-12-11 06:23:26

标签: c# asp.net asp.net-mvc twitter-bootstrap bootstrap-modal

我正在研究MVC。目前我的情况是,当我从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.");
    }

3 个答案:

答案 0 :(得分:1)

你可以尝试

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

答案 1 :(得分:0)

我建议您使用ViewModel绑定要查看的数据。 因此,您可以在保存数据后使用ModelState.Clear()方法清除模型。

您需要在控制器发布方法中使用它。

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

    return View(model);
}

答案 2 :(得分:0)

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

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