Hi people I have the following code (shown below) and I am trying to change it (its my code) so i can display a message box or some alert saying the book has been saved using an if statement in C# ASP.net MVC3
[HttpPost]
[ValidateInput(false)]
public ActionResult Create(BooksItem booksitem)
{
try
{
using (var db = new Booksforsale())
{
db.BooksItem.Add(booksitem);
db.SaveChanges();
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
Is there a way to change this to an If statement so when its saved a message box or an alert appears saying it has been saved. I would like real simple coding nothing to complex that will be hard for me to implement.
Thank You
I have tried the following:
[HttpPost]
[ValidateInput(false)]
If public ActionResult Create(BooksItem booksitem)
{
try
{
if using (var db = new Booksforsale())
{
db.BooksItem.Add(booksitem);
db.SaveChanges();
}
else viewbag.message="been added"
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
This has not worked thank you so much people for any help received really appreciate it thanks
You could store the message inside
TempDataso that it is available on the next request after you redirect:and inside the
Indexaction that you are redirecting to fetch the message fromTempDataand pass it to the view:and obviously display this message somewhere in the corresponding view: