HtmlHelper is null in Error.aspx master page
I have a custom Error.aspx page in my ASP.NET MVC application. The error page uses a master page (which in turn uses another master page), and in the master page there is a call to HtmlHelper:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Unsecure.Master" ... %>
...
Html.RenderPartial("LogOnUserControl")
My web.config is set up to use this error page for all errors:
<customErrors mode="RemoteOnly" defaultRedirect="/Views/Shared/Error.aspx" />
The trouble is that the Html property of the ViewMasterPage is null. My understanding is that this property is simply pulled from the ViewPage's Html property which is also null. Thus, any attempt to call a partial method against the HtmlHelper fails with a NullReferenceException开发者_运维技巧.
Why is the HtmlHelper null?
Does your MasterPage Page Directive look like this:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
without the Inherits attribute Html.* doesn't exist.
精彩评论