Reputation: 397
I create a feedback form and send it via email to admin by SMTP Server
. I have sent it successfully. Now I want to display a Email sent succeed
Message, after sending the email. I am using Response.Write
but it is not working well. I have used Ajax
, Jquery
and many other solutions for this purpose but they are not showing me good results.
FeedbackController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Name,Email,Comments")] Feedback feedback, string Message)
{
if (ModelState.IsValid)
{
bool result = false;
db.Feedbacks.Add(feedback);
db.SaveChanges();
result = SendEmail("[email protected]", "Feedback", "<p>Hi Admin,<br/>My name is "+ feedback.Name + ". <br/> E_mail ID: " + feedback.Email + "<br/><br/>" + feedback.Comments + "<br/>Kind Regards,<br/>" + feedback.Name + "</p>");
Response.Write("Email sent succeed");
ModelState.Clear();
return View("Create");
}
return View(feedback);
}
Upvotes: 0
Views: 290
Reputation: 6866
You could do something like:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Name,Email,Comments")] Feedback feedback, string Message)
{
if (ModelState.IsValid)
{
//your code
TempData["EmailSent"] = "Email sent succeed";
return View("Create");
}
return View(feedback);
}
In your Create View
@if (TempData["EmailSent"] != null)
{
<p>@TempData["EmailSent"].ToString()</p>
}
This is just one way of doing it you can make use of ViewBag
property to achieve this too
Upvotes: 1