简体   繁体   中英

Displaying a data saved successfully message in ASP.Net MVC

I am new to ASP.NET MVC 4.

I am trying to Toggle a div or p tag on the basis of a condition. I got the answer to display the tags using tempdata like so,in the Index Action Method of Home Controller

@if (TempData["notice"] != null) {
            <p id="para">@TempData["notice"]</p>

I am setting the Tempdata in another Action Method of another controller

TempData["notice"] = "Successfully registered";
                    return RedirectToAction("Index", "Home");

Once the control is sent back tothe index method,the paragraph is displayed correctly. I was wondering ,if there was a way to hide it now.

I know,we can use

document.getElementById('para').style.display = "none";

If I use this,I wont be able to see the para even after redirect. Kindly guide me in the right direction.

You can use jQuery hide and delay methods. Code below hides your message with delay in 2 seconds ( .delay(2000) )

@if(TempData["notice"] != null) {
   <p id="para">@TempData["notice"]</p>
}

<script type="text/javascript">
   $(function(){
      $('#para').delay(2000).hide(500);
   });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM