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 = "[email protected]"; 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("[email protected]", "Web Contact Form"); oMail.To.Add("[email protected]"); 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 protected]", "********", "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(); }