Mvc RenderPartial 到 Spark 视图
抱歉,如果还有其他问题涉及此问题。
这是我的问题。
我正在使用 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"> </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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下
有效!
Use following
It works!
您可以包含空引用异常的完整堆栈吗?
通过调试,您应该能够准确确定触发异常的原因。您应该尝试的一件事是将调试器设置为在所有异常发生时中断(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.