Asp.net 找不到Sitecore 7.2方法:“System.String Sitecore.Data.Fields.ImageField.get_Src()

Asp.net 找不到Sitecore 7.2方法:“System.String Sitecore.Data.Fields.ImageField.get_Src(),asp.net,sitecore,.net-4.5,sitecore7.2,Asp.net,Sitecore,.net 4.5,Sitecore7.2,我们最近将开发网站从Sitecore CMS 6.6更新为Sitecore CMS 7.2。这样一来,我们就无法加载网站上包含几乎所有图片的任何页面!,返回堆栈跟踪错误: [MissingMethodException: Method not found: 'System.String Sitecore.Data.Fields.ImageField.get_Src()'.] [TargetInvocationException: Property accessor 'ImgURL' on ob

我们最近将开发网站从Sitecore CMS 6.6更新为Sitecore CMS 7.2。这样一来,我们就无法加载网站上包含几乎所有图片的任何页面!,返回堆栈跟踪错误:

[MissingMethodException: Method not found: 'System.String Sitecore.Data.Fields.ImageField.get_Src()'.]

[TargetInvocationException: Property accessor 'ImgURL' on object 'Siteworx.Domain.Modules.HomeCarousel' threw the following exception:'Method not found: 'System.String Sitecore.Data.Fields.ImageField.get_Src()'.']
现在,我们拥有的代码应该生成图像URL,并且在更新之前一直在工作,如下所示:

public string ImgURL
{
    get { return new SCTypes.Image(this, "image").URL; }
}
我很难弄清楚这里到底出了什么问题,到目前为止,在这个问题上,我几乎没有找到任何像样的参考资料。如果有人能把我拉向正确的方向,我将永远感激

更新-2014年8月20日

好,

因此,我将上述代码更新为:

public string ImgURL
    {

        //get { return new SCTypes.Image(this, "image").URL; }
        get
        {
            string src = string.Empty;

            Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
            Sitecore.Data.Items.Item HomeCarousel = master.GetItem("/sitecore/content/modules/home/carousel items");
            Sitecore.Data.Fields.ImageField imageField = HomeCarousel.Fields["imagefield"];

           if (imageField != null && imageField.MediaItem != null)
            {
                Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);
                src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));
               // src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(image);
           }

            return src;

        }
页面现在加载,但没有图像。在查看图像应位于何处的html时,我看到:

<img src = "">

这意味着图像的URL没有在IF语句中设置。当我尝试在不使用IF语句的情况下构建代码并加载页面时,StackTrace会返回一个空引用错误。

Um。如果您在没有If语句的情况下构建它,并且最终出现空引用错误,那么这仅仅意味着imageField和/或imageField.MediaItem确实为空。IF语句只允许它测试null并返回空字符串,它成功地做到了这一点

因此,这表明问题进一步倒退。我不是Sitecore开发人员&我不知道API,所以我需要在这里进行几分钟的研究……但我从Sitecore内容API食谱中看到一件事:

您的master.GetItem/sitecore/content/modules/home/carousel items;可能需要是master.GetItem/sitecore/content/modules/home/carousel;在接下来的时间里,我们将抓住必要的细节。请参阅第3.4节“如何访问媒体项”


祝你好运

好吧,原来我的代码是正确的,只是放错地方了。这两条线:

Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);
src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));
在单独的帮助程序代码文件中需要,代码将在该文件中返回此信息。_imageField.Src;已定位,可在站点范围内恢复所有图像。不推荐使用的是.Src,当替换为两行时,再加上还原被认为有问题的原始代码{return new SCTypes.Imagethis,image.URL;}问题就解决了