Javascript 从

Javascript 从,javascript,asp.net-mvc,validation,Javascript,Asp.net Mvc,Validation,这是我在视图中的表格。。 SendCall是controller中发送电子邮件的方法 @using (Html.BeginForm("SendCall", "Home", FormMethod.Post, new { id = "email-form" })) { <label>Name</label> <input type="text" id="name" value=""/><span class="require"> *</

这是我在视图中的表格。。 SendCall是controller中发送电子邮件的方法

@using (Html.BeginForm("SendCall", "Home", FormMethod.Post, new { id = "email-form" }))
    {

<label>Name</label>
<input type="text" id="name" value=""/><span class="require"> *</span>
 <label>Email:</label>
<input id="Email" type="text" />

<input type="submit" value="Submit" >
    }

有人能建议我如何验证此表单吗?通过在ajax代码中添加一些代码?我想要客户端验证,而不是不引人注目的

客户端验证+不使用unobtrusive=您必须编写自己的javascript验证代码。这对你来说是一个很好的起点。
 [HttpPost]
        public ActionResult SendCall(string Date, string Phone, string Name, string Email)
        {
            string username = "xxxxxx@gmail.com";
            string password = "********";
            NetworkCredential loginInfo = new NetworkCredential(username, password);
            MailMessage msg = new MailMessage();
            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;

            string message =  Name + Email; //I have shortened this line. 

            try
            {
                msg.From = new MailAddress("yourname@gmail.com", "My Website");
                msg.To.Add(new MailAddress("email@gmail.com"));
                msg.Subject = "Contact Message";
                msg.Body = message;
                msg.IsBodyHtml = true;

                smtpClient.Send(msg);
                return Content("Your message was sent successfully!");
            }
            catch (Exception)
            {
                return Content("There was an error... please try again.");
            }
        }