naprawiony mailsener

This commit is contained in:
nlitkowski 2018-12-20 01:22:51 +01:00
parent 7ef186c12b
commit 3607ce2f2b
3 changed files with 24 additions and 6 deletions

View File

@ -7,20 +7,32 @@ using Newtonsoft.Json;
namespace MailSender.Controllers namespace MailSender.Controllers
{ {
[RoutePrefix("")]
public class HomeController : Controller public class HomeController : Controller
{ {
[HttpPost] [HttpPost]
public ActionResult Index([System.Web.Http.FromBody]MailDTO.MailDTO mail) public ActionResult Index([System.Web.Http.FromBody]MailDTO.MailDTO mail)
{ {
var model = new Models.MailModel(mail); var model = new Models.MailModel(mail);
return View(model); TempData.Add("mailMod", model);
return View(model);
}
[HttpGet]
public ActionResult Index()
{
if(TempData["mailMod"] != null)
{
return View(TempData["mailMod"]);
}
return View(new Models.MailModel());
} }
[System.Web.Http.HttpGet] [System.Web.Http.HttpGet]
public ActionResult Error(string errMsg) public ActionResult Error(string errMsg)
{ {
ViewData.Add("errMsg", errMsg); TempData.Add("errMsg", errMsg);
return View(); return RedirectToAction("Index");
} }
[System.Web.Mvc.HttpPost] [System.Web.Mvc.HttpPost]

View File

@ -30,6 +30,10 @@ namespace MailSender.Models
[StringLength(500, ErrorMessage = "Message has to have between 1 and 500 chars", MinimumLength = 1)] [StringLength(500, ErrorMessage = "Message has to have between 1 and 500 chars", MinimumLength = 1)]
public string Content { get; set; } public string Content { get; set; }
public MailModel()
{
Content = EMailTo = Subject = string.Empty;
}
public MailModel(MailDTO.MailDTO DTO) public MailModel(MailDTO.MailDTO DTO)
{ {

View File

@ -4,9 +4,11 @@
} }
@if (ViewData.ContainsKey("mailErr")) @if (TempData["mailErr"] != null)
{ {
<h3>Error: @ViewData["mailErr"]</h3> string errStr = TempData["mailErr"] as string;
<h3>Error: @TempData["mailErr"]</h3>
TempData["mailErr"] = null;
} }
@using (Html.BeginForm("Send", "Home", FormMethod.Post)) @using (Html.BeginForm("Send", "Home", FormMethod.Post))