saan mughal

saan mughal

  • NA
  • 12
  • 0

Bootstrap modal is not appearing when on form save using ASP.NET MVC

Mar 14 2021 1:26 PM
Hello everyone,
 
I am quite new to asp.net mvc, I am trying to display a bootstrap modal after I save the data. but its not showing modal or the modal disappears in a blink.
 
please see my code
 
thanks for the help in advance.
 
What I have tried:
 
controller action:
  1. [HttpPost]  
  2. [ValidateAntiForgeryToken]  
  3. public ActionResult AddNew(ProductModel pm)  
  4. {  
  5. if (ModelState.IsValid)  
  6. {  
  7. int result = IProductRep.Add(pm);  
  8. if (result <= 0)  
  9. {  
  10. return HttpNotFound();  
  11. }  
  12. else  
  13. {  
  14. ViewBag.Saved = "saved";  
  15. }  
  16. }  
  17. return View();  
  18. }  
view : (button is in the form with form method post)
  1. <input type="submit" class="btn btn-primary float-right shadow" value="Save" data-toggle="modal" data-target="#exampleModal">  
  2. @if (ViewBag.Saved != null)  
  3. {  
  4. <div class="modal fade" id="exampleModal">  
  5. <div class="modal-dialog modal-dialog-centered">  
  6. <div class="modal-content">  
  7. <div class="modal-header">  
  8. <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>  
  9. <span>×</span> </div>  
  10. <div class="modal-body"> New product has been saved successfully. </div>  
  11. <div class="modal-footer"> Close Save changes </div>  
  12. </div>  
  13. </div>  
  14. </div>  
  15. }  

Answers (2)