Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Handle Error using action filter in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 36
    Comment on it

    In MVC we have different kind of filters available for different purpose.

     

    One of the filters that is available is for handling the errors known as the error filter.

     

    We can handle that error in the same action or by redirecting it to another view or page we have made for handling and displaying errors.

     

    [HandleError]
    public class ActionFilterDemoController : Controller
    {
       public ActionResult Index()
         {
            throw new NullReferenceException();
         }
    
       public ActionResult About()
         {
            return View();
         }
    }

     

    We also can navigate it to some other view on finding the error.

     

    [HandleError]
    public class ActionFilterDemoController : Controller
    {
       public ActionResult Index()
         {
            return RedirectToAction('Error');
         }
    
       public ActionResult About()
         {
            return View();
         }
    }

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: