Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7438239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:31:22+00:00 2026-05-29T10:31:22+00:00

Sorry if this has been addressed. I just can’t get it to work. I

  • 0

Sorry if this has been addressed. I just can’t get it to work. I have a email contact form. I have the form working ok. It is sending an email. However, after the form is submitted I was either a message to pop up or be redirected to a different page saying that their email was sent successfully and we’ll respond as we can. I’ve tried RedirectActionTo and some other things, but I cannot get it to work. Here is my code.

       public ActionResult ContactForm(ContactModel emailModel)
    {            
            MailMessage oMail = new MailMessage();

            oMail.From = new MailAddress("no-reply@domain.com", "Web Contact Form");
            oMail.To.Add("email@domain.com");
            oMail.Subject = emailModel.Subject;
            string body = "Name: " + emailModel.Name + "\n"
                        + "Email: " + emailModel.Email + "\n"
                        + "Website: " + emailModel.Website + "\n"
                        + "Phone: " + emailModel.Phone + "\n\n"
                        + emailModel.Message;

            oMail.Body = body;

            if (SendMessage(oMail))
            {
                return RedirectToAction("Message");
            }
            else
            {
                return RedirectToAction("Error");
            }
            return View();
    }
    private bool SendMessage(MailMessage oMail)
    {
        SmtpClient client = new SmtpClient("relay-hosting.secureserver.net");
        client.Credentials = new NetworkCredential("email@domain.com", "********", "domaion.com");
        try
             {
                 client.Send(oMail);
                 return true;
             }
             catch (Exception ex)
             {
                 this.exception = ex;
                 return false;
             } }

}

Thank for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:31:23+00:00Added an answer on May 29, 2026 at 10:31 am

    The reason is because the action is completed without waiting for result.

    here is simplified version of my implementation

    after in your controller you can set up your response such as:

    public class ContactModel
            {
                public string Name { get; set; }
                public string Email { get; set; }
                public string Website { get; set; }
                public string Phone { get; set; }
                public string Message { get; set; }
                public string Subject { get; set; }
            }
    
            public ActionResult Index()
            {
                ViewData["Message"] = "Welcome to ASP.NET MVC!";
    
                ContactModel model = new ContactModel();
                model.Email = "test@email.com";
                model.Message = "message";
                model.Name = "name";
                model.Subject = "subject";
                model.Website = "http://test.com";
                ContactForm(model);
    
                return View();
            }
    
            /// <summary>
            /// Contacts the form.
            /// </summary>
            /// <returns>Returns view to display the form and fill</returns>
            [AcceptVerbs(HttpVerbs.Get)]
            public ActionResult ContactForm()
            {
                return View(new ContactModel());
            }
    
            /// <summary>
            /// Contacts the form.
            /// If model is valid we will go ahead and process emailing 
            /// </summary>
            /// <param name="emailModel">The email model.</param>
            /// <returns></returns>
            [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult ContactForm(ContactModel emailModel)
            {
                if (ModelState.IsValid)
                {
    
                    MailMessage oMail = new MailMessage();
    
                    oMail.From = new MailAddress("no-reply@domain.com", "Web Contact Form");
                    oMail.To.Add("email@domain.com");
                    oMail.Subject = emailModel.Subject;
                    string body = "Name: " + emailModel.Name + "\n"
                                  + "Email: " + emailModel.Email + "\n"
                                  + "Website: " + emailModel.Website + "\n"
                                  + "Phone: " + emailModel.Phone + "\n\n"
                                  + emailModel.Message;
    
                    oMail.Body = body;
    
                    if (SendMessage(oMail))
                    {
                        return RedirectToAction("Message");
                    }
                    else
                    {
                        return RedirectToAction("Error");
                    }
                }
                else
                {
                    return View(emailModel);
                }
            }
    
            /// <summary>
            /// Sends the message.
            /// </summary>
            /// <param name="oMail">The o mail.</param>
            /// <returns>Boolean success.</returns>
            private bool SendMessage(MailMessage oMail)
            {
                SmtpClient client = new SmtpClient("relay-hosting.secureserver.net");
                client.Credentials = new NetworkCredential("email@domain.com", "********", "domaion.com");
                try
                {
                    client.Send(oMail);
                    return true;
                }
                catch (Exception ex)
                {
                    this.exception = ex;
                    return false;
                }
            }
    

    The view is redirecting because i guess you have not split Type of the request over the method. and therefore its going straight to redirect.

    this is done by

    [AcceptVerbs(Http.Get)] or [AcceptVerbs(Http.Post)]

    hope this helps

    To pass message:

    TemData["message"] = "pass message between controllers like this"
    

    public AcionResult Message(string message){ //here choose
    ViewData[“message”] = TempData[“message];

    return View(); }

    or

        return RedirectToAction("Message", new{message = "pass message between controllers"});
     `enter code here`    where 
    public AcionResult Message(string message){
    //or if you are using parameter
    ViewData["message"] = message;
    
    
    return View();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this has been asked. Just like I can select in C# project
I'm sorry if this question has been asked. I have looked but can not
Sorry if this has been asked elsewhere. I have looked but can't find any
Sorry if this has been asked but can't find anything. I have a table
Im very sorry if this has been answered before but I have been looking
I've tried searching through search engines,MSDN,etc. but can't anything. Sorry if this has been
Sorry if this has already been answered, but I can't find it if so.
I am sorry if this has been posted before. I have searched many websites
Sorry if this has been asked, but how can I improve the following with
Sorry if this has been asked elsewhere, I've been looking and can't find it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.