I need to implement my own custom error page in MVC 4. Basically when users try to view Details of any product with non-existent productID, I want this custom error page.
I created my own custom error page NotFound.aspx
The inside content of this page is :
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Simple.Master" Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>" %> <asp:Content ID="errorTitle" ContentPlaceHolderID="TitleContent" runat="server"> Error </asp:Content> <asp:Content ID="errorContent" ContentPlaceHolderID="MainContent" runat="server"> <h2> Sorry, you requested a product that doesn't exist. Make sure you requested a valid ProductID </h2> </asp:Content> And then Applied the HandleError filter to my ActionMethod: Details as:
[HandleError(View="NotFound")] public ActionResult Details(int id) {... The problem is that, Always the default view : Views/Shared/Error.aspx is being called and not the new custom error page. Any thoughts ?