我的 mvc 网站上有反馈表,我将此表发送到电子邮件。
在我的控制器中,我创建了 ErrorMessage 以防电子邮件发送失败,并创建 SuccessMessage 以防电子邮件发送成功
/*Feedback*/
[HttpGet]
public ActionResult Feedback(string ErrorMessage)
{
if (ErrorMessage != null)
{
}
return View();
}
[HttpPost]
public ActionResult Feedback(FeedbackForm Model)
{
string ErrorMessage, SuccessMessage;
//email
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.BodyEncoding = Encoding.UTF8;
msg.Priority = MailPriority.High;
msg.From = new MailAddress(Model.Email, Model.Name);
msg.To.Add("tayna-anita@mail.ru");
msg.Subject = @Resources.Global.Feedback_Email_Title + " " + Model.Company;
string message = @Resources.Global.Feedback_Email_From + " " + Model.Name + "\n"
+ @Resources.Global.Feedback_Email + " " + Model.Email + "\n"
+ @Resources.Global.Feedback_Phone + " " + Model.Phone + "\n"
+ @Resources.Global.Feedback_Company + " " + Model.Company + "\n\n"
+ Model.AdditionalInformation;
msg.Body = message;
msg.IsBodyHtml = false;
//Attachment
if (Model.ProjectInformation != null && !(String.IsNullOrEmpty(Model.ProjectInformation.FileName)))
{
HttpPostedFileBase attFile = Model.ProjectInformation;
if (attFile.ContentLength > 0)
{
var attach = new Attachment(attFile.InputStream, attFile.FileName);
msg.Attachments.Add(attach);
}
}
SmtpClient client = new SmtpClient("denver.corepartners.local", 55);
client.UseDefaultCredentials = false;
client.EnableSsl = false;
try
{
client.Send(msg);
SuccessMessage = "Email sending was successful"
}
catch (Exception ex)
{
return RedirectToAction("Feedback", "Home", ErrorMessage = "Email sending failed");
}
return RedirectToAction("Feedback", "Home");
}
如何添加在我的视图中显示此消息?