Sunday 15 April 2012

c# - How to display error / result messages to the user upon an action -


I have been working on an application for some time and a minor problem arose.

I am so surprised

So far how have I been moving forward with an example:

  if (itemID == faucet) {ViewData [ "ErrorMessage"] = "The provided ID prompted an error, please try again. If the problem persists, contact your local administrator."; }   

Something very simple ... if we believe that the user remains in the same view

That's why I have any MVC "intelligent- Asking "Master": Is there a skilled, reusable way of displaying the message, can it be in any format? And can you tell that How do you do it?

Thanks!

If there is an error, then normal The At the moment, users should remain in the same view and do not redirect, so they can correct the error and try again. So you basically do the same:

  if (id = id ==) {ViewData ["ErrorMessage"] = "The provided id has bundled an error, please try again. If the problem persists, contact your local administrator. "; Return View (); // You probably have a model to include) Other {// Make your Action Return Redirect Tiection (" Some Action ");}   

All After that, just refer to the error message displayed to you:

The provided ID prompted an error. Please try again. If the problem persists , Contact your local administrator.

You may also consider using this as a Maybe it is not used unless it is used:

  if (itemID == null) {TempData ["ErrorMessage"] = "The ID provided is a The error is bored, please try again. If the problem persists, contact your local administrator. ";}   

It continues in all redirects and will be available after the request. So if you send the user through some complex series, then when a view finally comes to the TempData renders and checks for the value in "[ErrorMessage"] , even then it will be present there (and I think it will be destroyed after reading.) < / Div>

No comments:

Post a Comment