mari muthu

mari muthu

  • NA
  • 198
  • 107.4k

how to display the Error Message in Mvc ..?

May 5 2016 7:18 AM
 
 
 1.when i click the save ,save successfull message has to be come like this green Colour message box
 
2.when i click save if some Error have Error message also dispaly like this Red Colour MEssage box 
 
   hi i want to display the Error message like this Please tell me if you know this i tried so many ways but  i can show Error alert only please  help me for this i have given my code also please help me  
 
[HttpPost]
public ActionResult Index(MailModel objModelMail, HttpPostedFileBase fileUploader)
{
if (ModelState.IsValid)
{
Thread email = new Thread(delegate()
{
string from = "[email protected]"; //example:- [email protected]
using (MailMessage mail = new MailMessage(from, objModelMail.To))
{
mail.Subject = objModelMail.Subject;
mail.Body = objModelMail.Body;
if (fileUploader != null)
{
string fileName = Path.GetFileName(fileUploader.FileName);
mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
}
mail.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential networkCredential = new NetworkCredential(from, "XXXXXXX");
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCredential;
smtp.Timeout = int.MaxValue;
smtp.Port = 587;
smtp.Send(mail);
ViewBag.Message = "Sent";
}
});
email.IsBackground = true;
email.Start();
ParsingTemplate();
return View("Index", objModelMail);//I need that successful message here itself
}
else
{
return View();//i need that Error Message here itself
}
}
 

Answers (10)