2015-12-11 24 views
1

我正在致力於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."); 
    } 
+0

只是清除表單 - '$( '形式')得到(0).reset段();' –

回答

0

你應該清除你的模態div html,因爲你是從局部視圖重新生成模態。以下是刪除模態元素的代碼。

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

謝謝。它爲我工作 – Anabik

0

我建議你使用視圖模型的數據綁定到查看代碼。 因此,您可以使用ModelState.Clear()方法在保存數據後清除模型。

你需要在你的控制器post方法中使用這個。

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

    return View(model); 
} 
+0

插入操作需要一些字符串值作爲參數。它會繼續工作嗎? – Anabik

+0

@AnabikThakur編輯您的問題爲控制器actionmethod添加代碼 –

1

您可以嘗試

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