InterviewSolution
| 1. |
What are Filters in MVC |
|
Answer» When we want to be executed just prior to the action execution, when the USER sends the request to the controller, in this the user create the custom class which works as a filter where the developer writes the logic which will be implemented just prior to the action execution, By programming method we can apply filters to the actions ,There are different type of filter use in MVC :
When there is any kind of exception in an APPLICATION then the exception filter executes. HandleErrorAttribute ([HandlerError]) class is a built-in exception filter class in MVC framework. The HandleErrorAttribute class renders Error.cshtml which is inside the shared folder which is added by default during project creation when an unhandled exception OCCURS. [HandleError] public class HomeController : Controller { public ActionResult Index() { throw new Exception("This is unhandled exception"); return View(); } public ActionResult About() { return View(); } public ActionResult Contact() { return View(); } } |
|