Validation 未在MVC中验证或发送电子邮件

Validation 未在MVC中验证或发送电子邮件,validation,email,asp.net-mvc-4,gmail,Validation,Email,Asp.net Mvc 4,Gmail,我试图从我的MVC4站点发送电子邮件并进行验证,但什么都没有发生这是控制器 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Net.Mail; namespace DonsSolution.Controllers { public class SendMailerController : Control

我试图从我的MVC4站点发送电子邮件并进行验证,但什么都没有发生这是控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;


namespace DonsSolution.Controllers
{
public class SendMailerController : Controller
{
    //
    // GET: /SendMailer/

public ActionResult Index()
{
        return View();
 }
public static bool SendGmail(string subject, string content, string[] recipients,string         ........from)
    {
        bool success = recipients != null && recipients.Length > 0;

        if (success)
        {
            SmtpClient gmailClient = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential("youremail@gmail.com","password")

            };


            using (MailMessage gMessage = new MailMessage(from, recipients[0], subject,     content))
            {
                for (int i = 1; i < recipients.Length; i++)
                    gMessage.To.Add(recipients[i]);

                try
                {
                    gmailClient.Send(gMessage);
                    success = true;
                }
                catch (Exception) { success = false; }
            }
        }
        return success;
    }
}
它正在联系人页面下的部分视图中传递

@model DonsSolution.Models.MailModel

<h2>Ask the Coach a question</h2>
<fieldset>
<legend>
Ask me a question?
</legend>
@using (Html.BeginForm(FormMethod.Post))
{
    @Html.ValidationSummary()

    <p>@Html.Label("From")
        @Html.TextBoxFor(m => m.From)</p>

    <p>@Html.Label("Subject") </p>
    <p>@Html.TextBoxFor(m => m.Subject)</p>
    <p>@Html.Label("Body")</p>
    <p>@Html.TextAreaFor(m => m.Body)</p>
    <input type="submit" value="Send" />
}
@model DonsSolution.Models.MailModel
问教练一个问题
问我一个问题?
@使用(Html.BeginForm(FormMethod.Post))
{
@Html.ValidationSummary()
@Html.Label(“From”)
@Html.TextBoxFor(m=>m.From)

@Html.Label(“主题”)

@Html.TextBoxFor(m=>m.Subject)

@Html.Label(“Body”)

@Html.TextAreaFor(m=>m.Body)

}


一般来说,我对编码非常陌生。我真的需要你的帮助。我尝试过很多不同的选择,但都没有效果。请帮忙

这里有两个问题。最好将它们分为两个问题;一个用于验证,另一个用于发送电子邮件。确定将更改它。谢谢,只要电子邮件问题得到回答,这是最重要的。
@model DonsSolution.Models.MailModel

<h2>Ask the Coach a question</h2>
<fieldset>
<legend>
Ask me a question?
</legend>
@using (Html.BeginForm(FormMethod.Post))
{
    @Html.ValidationSummary()

    <p>@Html.Label("From")
        @Html.TextBoxFor(m => m.From)</p>

    <p>@Html.Label("Subject") </p>
    <p>@Html.TextBoxFor(m => m.Subject)</p>
    <p>@Html.Label("Body")</p>
    <p>@Html.TextAreaFor(m => m.Body)</p>
    <input type="submit" value="Send" />
}