本文介绍了提交后的明确表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在提交后清除表格,



我试试看这个:



Hi,

I want to clear the form after submit,

I try it like this:

[HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Contact(EmailFormModel model)
        {
            string message2 = "There are a few errors";
            if (ModelState.IsValid)
            {
                message2 = "Thanks! We'll get back to you soon.";
                var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                var message = new MailMessage();
                message.To.Add(new MailAddress("[email protected]")); //replace with valid value
                message.Subject = "Your email subject";
                message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
                message.IsBodyHtml = true;
                using (var smtp = new SmtpClient())
                {
                    await smtp.SendMailAsync(message);


                }

            }
            if (Request.IsAjaxRequest())
            {
                return new JsonResult { Data = new { success = true, message = message2 } };
            }

            TempData["Message"] = message2;

            ModelState.Clear();
            return View(model);
        }





谢谢



Thank you

推荐答案


这篇关于提交后的明确表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:17