Mvc RenderPartial 到 Spark 视图

发布于 2024-08-23 08:34:41 字数 4010 浏览 2 评论 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,但我收到错误消息“对象引用未设置到对象的实例”。

Menu.ChildItems 的

堆栈跟踪计数 = 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

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="menuItem.ChildItems != null">
       <li class="drop">   
        <a href="${menuItem.Url}" alt="${menuItem.Tooltip}">${menuItem.DisplayText}</a>
        <span class="toggle"> </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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你不是我要的菜∠ 2024-08-30 08:34:41

使用以下

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

有效!

Use following

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

It works!

疯到世界奔溃 2024-08-30 08:34:41

您可以包含空引用异常的完整堆栈吗?

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文