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");
}
ビューにこのメッセージを表示するにはどうすればよいですか?