Passing messages to the user in MVC2


Passing messages to the user in MVC2



I am using ASP.NET MVC2 for my project. I want to send the user confirmation messages after actions.

Ideally: User clicks on a link with a query string (i.e. a link to delete an entry) The controller does what the link says, creates the success message, and uses RedirectToAction to get rid of the query string from the URL. The new action displays the success message.

It was suggested I use a model error to do this, however I do not think that will work in this situation.

Thanks.




ASP.NET MVC: Why is `ToMvcHtmlString` not public?

1:



What is a good strategy for dealing with large javascript code in asp.net MVC projects?
You could use TempData:.
How to NOT route files & directories to ASP.NET MVC
public ActionResult Index() {     string message = TempData["message"] as string ?? string.Empty;     // send the message as model so that the view can print it out     return View("index", message); }  [HttpPost] public ActionResult DoWork() {     // do some work     TempData["message"] = "Work done!";     return RedirectToAction("index"); } 
Internally TempData uses session in order to persist the information but it is automatically purged after the next request, so it will be available only on the next request following the storage..
Object gets disconnected from nHibernate session after TryUpdateModel is called


Validating that a form input is not empty


Value from Hidden Input field as an Actionlink Parameter

2:



How to send jQuery $.get so the Model Binder can bind a string to a parameter?
First of all DON'T USE GET REQUESTS TO MODIFY DATA! Imagine a search engine indexing your site and visiting all of the delete links..
Adding check boxes to each row on MVCcontrib Grid
Second, why can't the target action return a view to show the success/failure message?.


3:


I use TempData with a message in my Site.Master file:.
  <% if (TempData["Error"] != null)      { %>      <div id="errorMessage">         <%= Html.Encode(TempData["Error"]) %>     </div>    <% } %>     <% if (TempData["Warning"] != null)       { %>      <div id="warningMessage">         <%= Html.Encode(TempData["Warning"]) %>     </div>    <% } %> 
In my controller I can assign a value either to TempData["Error"] or to TempData["Warning"] and have them styled differently..



97 out of 100 based on 47 user ratings 397 reviews

@