开发者

Mvc RenderPartial to spark view

开发者 https://www.devze.com 2022-12-20 23:46 出处:网络
Sorry if there is another question that covers this. Here is my problem. I am using Html.RenderPartial, i am also using T4MVC.

Sorry if there is another question that covers this.

Here is my problem.

I am using Html.RenderPartial, i am also using T4MVC.

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

spark view:

 <ul class="menu">
     <for each="var menuItem in Menu.ChildItems">
      <if condition="m开发者_StackOverflow中文版enuItem.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>

The Menu has ChildItems but I get an error message Object reference not set to an instance of an object.

Menu.ChildItems has a Count = 5

Stack Trace

[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


Use following

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

It works!


Could you include the full stack of the null ref exception?

By debugging, you should be able to determine exactly what is triggering the exception. One thing you should try is to set the debugger to break on all exception (Ctrl-Alt-E brings up that dialog), so that you'll catch it as it happens. This should go a loong way to finding the root of the issue.

0

精彩评论

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