Sitecore MVC中的BeginRenderLink对象引用错误

时间:2016-08-30 19:00:53

标签: sitecore glass-mapper

以下代码抛出“未将对象引用设置为对象的实例”。错误,我无法弄清楚为什么。当我调试时,我的模型有我期待的数据。看起来很简单,不确定我做错了什么。

@using(BeginRenderLink(Model, x => x.Page, isEditable: true))
{
    @RenderImage(Model, x => x.IconImage, isEditable: true);
    @Editable(Model, x => x.Headline);
}

更新:如果我从BeginRenderLink块中取出以下两行,它们将按预期工作。希望这对你们其中一个人有意义......

@RenderImage(Model, x => x.IconImage, isEditable: true);
@Editable(Model, x => x.Headline);

堆栈跟踪

[NullReferenceException: Object reference not set to an instance of an object.]
   Glass.Mapper.Sc.Web.Mvc.GlassView`1.BeginRenderLink(T model, Expression`1 field, NameValueCollection attributes, Boolean isEditable) +36
   ASP._Page_Views_Websites_Pool_Components_IconLink_IconLink_cshtml.Execute() in c:\inetpub\wwwroot\PentairPoolTest\Website\Views\Websites\Pool\Components\IconLink\IconLink.cshtml:5
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +146
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +106
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +374
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +89
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +710

相关领域的数据模型:

/// <summary>
        /// The Page field.
        /// <para></para>
        /// <para>Field Type: General Link</para>       
        /// <para>Field ID: 50770754-ec0c-4ac3-a05c-44aa8a278f69</para>
        /// <para>Custom Data: </para>
        /// </summary>
        [GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.1")]
        [SitecoreField("Page")] 
        public virtual Link Page {get; set;}

    /// <summary>
            /// The IconImage field.
            /// <para></para>
            /// <para>Field Type: Image</para>      
            /// <para>Field ID: c5b9417e-2b29-461d-9e95-396fac25b3bb</para>
            /// <para>Custom Data: </para>
            /// </summary>
            [GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.1")]
            [SitecoreField("IconImage")] 
            public virtual Image IconImage {get; set;} 
            /// <summary>
            /// The Headline field.
            /// <para></para>
            /// <para>Field Type: Single-Line Text</para>       
            /// <para>Field ID: 16f2ca59-68b4-412d-a021-7fdceaa50cb1</para>
            /// <para>Custom Data: </para>
            /// </summary>
            [GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.1")]
            [SitecoreField("Headline")] 
            public virtual string Headline {get; set;} 

0 个答案:

没有答案