猿问

以下是关于Html.RenderPartial 报错的问题,具体该怎么解决呢》?

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

行 24: </div>--%>
行 25:
行 26: <% Html.RenderPartial("Header.ascx"); %>
行 27:
行 28: </div>

源文件: e:\gz_project\VS2008\Design\Design.Web\U\UserDomains\Home.aspx 行: 26

堆栈跟踪:

[NullReferenceException: 未将对象引用设置到对象的实例。]
System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName) +10
ASP.u_userdomains_home_aspx.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in e:\gz_project\VS2008\Design\Design.Web\U\UserDomains\Home.aspx:26
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +163
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

江户川乱折腾
浏览 354回答 1
1回答

慕容3067478

如果你的partial(本例中也就是Header.ascx)是在当前请求的controller下(也就是位于目录/Views/nameController下)或共享目录下(也就是/Views/Shared下),那么你只要把后缀.ascx去掉就行了,也就是把你的第26行换成<% Html.RenderPartial("Header.ascx"); %>。如果你的partial位于其它位置,那么你需要引用全虚拟目录,目录依你项目而定,形式如下:<%: Html.Partial("~/Views/Shared/Partials/MyOtherPartial.ascx") %>注意,这个时候需要.ascx后缀。
随时随地看视频慕课网APP
我要回答