using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SteamKing.Models;
using System.Net.Mail;
namespace SteamKing.Controllers
{
public class Contact_UsController : Controller
{
//
// GET: /Contact_Us/
[HttpGet]
public ViewResult Index()
{
return View();
}
[HttpPost]
public ViewResult Index(Contact_Us Index)
{
if (ModelState.IsValid)
{
//I need the Email sender to go here.
return View("Thanks", Index);
}
else
{
return View();
}
}
}
}
Also here is my View:
@model SteamKing.Models.Contact_Us
@{
ViewBag.Title = "Contact_Us";
}
<h2>Contact_Us</h2>
<fieldset>
<legend>Send Steam King a Message!</legend>
@using (Html.BeginForm())
{
@Html.ValidationSummary()
<p>First Name:</p>
<p>@Html.TextBoxFor(m => m.firstName)</p>
<p>Last Name:</p>
<p>@Html.TextBoxFor(m => m.lastName)</p>
<p>Phone Number:</p>
<p>@Html.TextBoxFor(m => m.phoneNumber)</p>
<p>Email:</p>
<p>@Html.TextBoxFor(m => m.email)</p>
<p>Are you a previous customer:</p>
@Html.DropDownListFor(x => x.previousCustomer, new[] {
new SelectListItem() {Text = "Yes, I am", Value = bool.TrueString},
new SelectListItem() {Text = "No, I am not", Value = bool.FalseString}
}, "Choose an option")
<p>Message:</p>
<p>@Html.TextAreaFor(m => m.message, new { @cols = 80, @rows = 10 })</p>
<input type ="submit" value="Submit" />
}
</fieldset>
so i need to be able to send that form to the Clients email address letting them know who sent it and what was said in the message
repeater09
Member
12 Points
20 Posts
Re: Asp.Net MVC 3 Send Razor contact form to email
Apr 27, 2012 02:02 AM|LINK
None of this seems to work.
They are both using System.Web.Mail
I need to know how to use the new System.Net.Mail
Here is my controller if this my help:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using SteamKing.Models; using System.Net.Mail; namespace SteamKing.Controllers { public class Contact_UsController : Controller { // // GET: /Contact_Us/ [HttpGet] public ViewResult Index() { return View(); } [HttpPost] public ViewResult Index(Contact_Us Index) { if (ModelState.IsValid) { //I need the Email sender to go here. return View("Thanks", Index); } else { return View(); } } } }Also here is my View:
@model SteamKing.Models.Contact_Us @{ ViewBag.Title = "Contact_Us"; } <h2>Contact_Us</h2> <fieldset> <legend>Send Steam King a Message!</legend> @using (Html.BeginForm()) { @Html.ValidationSummary() <p>First Name:</p> <p>@Html.TextBoxFor(m => m.firstName)</p> <p>Last Name:</p> <p>@Html.TextBoxFor(m => m.lastName)</p> <p>Phone Number:</p> <p>@Html.TextBoxFor(m => m.phoneNumber)</p> <p>Email:</p> <p>@Html.TextBoxFor(m => m.email)</p> <p>Are you a previous customer:</p> @Html.DropDownListFor(x => x.previousCustomer, new[] { new SelectListItem() {Text = "Yes, I am", Value = bool.TrueString}, new SelectListItem() {Text = "No, I am not", Value = bool.FalseString} }, "Choose an option") <p>Message:</p> <p>@Html.TextAreaFor(m => m.message, new { @cols = 80, @rows = 10 })</p> <input type ="submit" value="Submit" /> } </fieldset>so i need to be able to send that form to the Clients email address letting them know who sent it and what was said in the message