Hi, while coding in asp.net C# MVC 2.0, how to show error messages let say there is try {}..Catch{} or If Else ... then if i want to show error messages , then how can i code?
+1
A:
Just return an error in your ViewData
:
public ActionResult Index(int id)
{
try
{
// Do something that causes an error
}
catch (Exception ex)
{
ViewData["Error"] = ex.Message;
}
return View();
}
And get it within your page by using ViewData["Error"]
.
GenericTypeTea
2010-09-08 08:08:49