Using MVC Framework with C# coding. The views are written in standard HTML code. I require a confirmation message saying "Your message has been sent" once the user clicks the submit button
Here is the controller:
public ActionResult Index(ContactViewModel contactVM){
        if (!ModelState.IsValid)
        {
            string url = Request.UrlReferrer.AbsolutePath+ "#contact";
            return View();
        }
        else
        {
            var contact = new Contact
            {
                Name = contactVM.Name,
                Email = contactVM.Email,
                Subject = contactVM.Subject,
                Message = contactVM.Message
            };
            new Email().Send(contact);
            return RedirectToAction("Index");
        }
Here is the View:
<input type="submit" class="submit_btn left" name="Submit" id="submit" value="Submit"/>
<input type="reset" class="submit_btn right" name="Reset" id="reset" value="Reset" />
Kindly assist.
Instead of RedirectToAction(), return View :
    new Email().Send(contact);
    ViewBag.Message = "Message Sent"; 
    return View();
In View:
@if(ViewBag.Message != null)
{
<script>
$(document).ready(function(){
alert('@ViewBag.Message');
});
</script>
}
                        Add Inside controller
        ViewBag.IsEmailSent=true;
public ActionResult Index(ContactViewModel contactVM){
            if (!ModelState.IsValid)
            {
                string url = Request.UrlReferrer.AbsolutePath+ "#contact";
                return View();
            }
            else
            {
                var contact = new Contact
                {
                    Name = contactVM.Name,
                    Email = contactVM.Email,
                    Subject = contactVM.Subject,
                    Message = contactVM.Message
                };
                new Email().Send(contact);
                ViewBag.IsEmailSent=true;
                return RedirectToAction("Index");
            }
Index.cshtml page
   @if(ViewBag.IsEmailSent)
    {
    <script>
$(function(){
     $("#successModal").modal('show'); });
    </script>
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With