我需要在MVC 4中实现我自己的自定义错误页面.基本上,当用户尝试查看具有不存在的productID的任何产品的详细信息时,我想要这个自定义错误页面.
<%@ 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>
然后将HandleError过滤器应用于我的ActionMethod:Details as:
[HandleError(View="NotFound")] public ActionResult Details(int id) {...
问题是,始终是默认视图:正在调用Views / Shared / Error.aspx,而不是新的自定义错误页面.有什么想法吗 ?