No problem. It looks like the issue is that you are referencing a variable called Model. However, in your case the model being passed in as input parameter is called Index. The parameter that gets passed into the action method is the model that gets binded,
so you need to change your action method to this:
[HttpPost]
public ViewResult Index(Contact_Us Index) // Your model is passed in here
{
if (ModelState.IsValid)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("server@steamkingal.com");
message.To.Add(new MailAddress("services@steamkingal.com"));
message.Subject = "This is my subject";
// You need to use Index because that is the name declared above
message.Body = Index.message;
SmtpClient client = new SmtpClient();
client.Send(message);
return View("Thanks", Index);
}
else
{
return View();
}
}
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Asp.Net MVC 3 Send Razor contact form to email
Apr 28, 2012 04:50 AM|LINK
No problem. It looks like the issue is that you are referencing a variable called Model. However, in your case the model being passed in as input parameter is called Index. The parameter that gets passed into the action method is the model that gets binded, so you need to change your action method to this:
[HttpPost] public ViewResult Index(Contact_Us Index) // Your model is passed in here { if (ModelState.IsValid) { MailMessage message = new MailMessage(); message.From = new MailAddress("server@steamkingal.com"); message.To.Add(new MailAddress("services@steamkingal.com")); message.Subject = "This is my subject"; // You need to use Index because that is the name declared above message.Body = Index.message; SmtpClient client = new SmtpClient(); client.Send(message); return View("Thanks", Index); } else { return View(); } }Blog | Twitter : @Hattan