2014-01-22 19 views
2

我真的很少使用JavaScript和JQuery,我需要一些幫助來清除我遇到的一個簡單問題。MVC4 + jQuery淡出通知div

我根據保存到數據庫的結果動態加載下面的div,並希望用戶通知在一兩秒後淡出。我編譯並運行的腳本沒有問題,但不會淡出div。

你能告訴我我錯過了什麼,或者是否有更好的方法來做到這一點。

控制器

public ActionResult Index(IList<Datapoint> model) 
{ 
    if (ModelState.IsValid) 
    { 
     try 
     { 
      ctx.SaveChanges(model); 
      ViewBag.Notification = "Save Successful"; 
     } 
     catch (Exception ex) 
     { 
      ViewBag.Notification = "Save Failed"; 
     }    
    } 

    return View(model); 
} 

的Html

@if(!ViewBag.Notification.ToString().Equals(string.Empty)) 
{ 
    <div id="Notification" class="large-4 large-offset-6 columns"> 
     <h5 class="button [secondary success alert] round">@ViewBag.Notification.ToString()</h5> 
    </div> 
} 

<script src="~/Scripts/jquery-1.8.2.min.js"></script> 
<script> 
    $("Notification").fadeOut(1000); 
</script> 

回答

4

你需要id選擇之前,使用#

<script> 
    $("#Notification").fadeOut(1000); 
    //.^........... 
</script> 

http://api.jquery.com/id-selector/

+1

謝謝,不敢相信我錯過了那一個。 –