0

抱歉,如果还有其他问题涉及此问题。

这是我的问题。

我正在使用 Html.RenderPartial,我也在使用 T4MVC。

<%Html.RenderPartial(MVC.Shared.Views.MainMenu, Model.Menu); %>

火花视图:

 <ul class="menu">
     <for each="var menuItem in Menu.ChildItems">
      <if condition="menuItem.ChildItems != null">
       <li class="drop">   
        <a href="${menuItem.Url}" alt="${menuItem.Tooltip}">${menuItem.DisplayText}</a>
        <span class="toggle">&nbsp;</span>
         <ul>
         <for each="var childItem in menuItem.ChildItems">
          <if condition="childItem.ApplicationName == @'Platform'">
           <li> 
            <a href="${childItem.Url}" alt="${childItem.Tooltip}">${childItem.DisplayText}</a>
           </li> 
          </if>
         </for>
         </ul>
       </li>
      </if>
      <else>
       <li>   
        <a href="${menuItem.Url}" alt="${menuItem.Tooltip}">${menuItem.DisplayText}</a>
       </li>
      </else> 
     </for>
    </ul>

菜单有 ChildItems,但我收到错误消息 Object reference not set to an object of an instance。

Menu.ChildItems 有一个 Count = 5

堆栈跟踪

[NullReferenceException: Object reference not set to an instance of an object.]
   BackOffice.Controllers.Viewa0321bdb3ead4545be250290e6473518.RenderViewLevel0() +103
   BackOffice.Controllers.Viewa0321bdb3ead4545be250290e6473518.RenderView(TextWriter writer) +83
   Spark.Web.Mvc.SparkView.Render(ViewContext viewContext, TextWriter writer) in c:\Projects\spark\src\Spark.Web.Mvc\SparkView.cs:134
   System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, ViewEngineCollection viewEngineCollection) +319
   System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName, Object model) +54
   ASP.views_centraldownload_listalldownloads_aspx.__RenderContent4(HtmlTextWriter __w, Control parameterContainer) in e:\Dev\Saffire\Platform\platform\src\BackOffice\Views\CentralDownload\ListAllDownloads.aspx:10
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   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
   ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in e:\Dev\Saffire\Platform\platform\src\BackOffice\Views\Shared\Site.Master:40
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   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.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
4

2 回答 2

1

使用以下

#Html.RenderPartial(MVC.Shared.Views.MainMenu, Model.Menu);

有用!

于 2010-06-04T13:00:56.700 回答
0

您能否包括 null ref 异常的完整堆栈?

通过调试,您应该能够准确确定触发异常的原因。您应该尝试的一件事是将调试器设置为在所有异常上中断(Ctrl-Alt-E 显示该对话框),以便您在它发生时捕获它。这应该很容易找到问题的根源。

于 2010-02-25T18:26:08.363 回答