Sunday, September 24, 2023

sweetalerts with @ViewBag.Message mvc 5


How To Show success alert with sweetalert 


Show Success Message On Create, Edit  Mvc 5

Controller:

Add  ViewBag.Message in  Controller --> ActionResult Edit, Create

[HttpPost]

        public ActionResult Edit(model)

        {

              --your Code here

                ViewBag.Message = "Details Edited successfully";

            }

           return View();

        }


View:

 From your Scripts lib folder

 <script src="~/Scripts/jquery-1.11.3.min.js">  </script>

CDN

 <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.7.28/dist/sweetalert2.min.css />

 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.7.28/dist/sweetalert2.all.min.js">

</script>


    @if (ViewBag.Message != null)

    {

        <script type="text/javascript">

             $(window).load(function () {

                new swal({                    

                    text: "@ViewBag.Message",

                    type: "success"

                }).then(okay => {

                    if (okay) {

                        window.location.href = "@Url.Action("Index", "any")";

                    }

                });

  });


        </script>


sweetalert  alert



Save a PDF generated from html2pdf in C#, MVC , html2pdf , Ajax code

 To save on server or disk a PDF generated from HTML in C# code example, you can use the      html2pdf js script     html2pdf   converts any...