HtmlHelper is null in the main Error.aspx page

I have a custom Error.aspx page in my ASP.NET MVC application. The error page uses the main page (which, in turn, uses a different main page), and on the main page there is an HtmlHelper call:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Unsecure.Master" ... %>
...
Html.RenderPartial("LogOnUserControl")

My web.config is configured to use this error page for all errors:

<customErrors mode="RemoteOnly" defaultRedirect="/Views/Shared/Error.aspx" />

The problem is that the Html ViewMasterPage property is NULL. I understand that this property is simply pulled from the ViewPage Html property, which is also null. Thus, any attempt to invoke a partial method against an HtmlHelper fails with a NullReferenceException.

Why is HtmlHelper null?

+3
source share
1 answer

Does your directive comply with the MasterPage page:

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>  

without the Inherits Html attribute. * does not exist.

0
source

Source: https://habr.com/ru/post/1727408/


All Articles