开发者

HtmlHelper is null in Error.aspx master page

开发者 https://www.devze.com 2022-12-15 07:54 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消