Umbraco Razor 模板错误
我对 Umbraco 中的 Razor 模板(以及一般情况)不太熟悉,但我更喜欢使用它而不是 XSLT 文件。但是,我遇到了一个我不知道如何解决的问题。我收到以下消息:
An unknown error occured while rendering the following code:
System.NullReferenceException: Object reference not set to an instance of an object.
at RazorEngine.Dynamic.baeffbebc.Execute()
at RazorEngine.Templating.TemplateService.Parse[T](String template, T model, String name)
at umbraco.MacroEngines.RazorEngine.GetResult(String cacheIdentifier, String template, INode currentPage, String& result)
我的宏看起来像这样:
@using System
@using uComponents.Core
@using uComponents.Core.uQueryExtensions
@using System.Linq
@using umbraco.NodeFactory
@helper NoPictures()
{
<li>Pictures coming soon!</li>
}
@helper Pictures(String crop)
{
<li><a rel="photos" href="@crop" title="test">
<img src="@crop" class="shadow hovershadow"></a></li>
}
@{
var n = Node.GetCurrent();
var pictures = n.GetProperty("pictures").Value;
if(pictures.Length <= 0)
{
NoPictures();
}
else
{
var pictureNodes = pictures.Split(',');
foreach (var pictureNode in pictureNodes)
{
var node = new Node(Convert.ToInt32(pictureNode));
var photoId = node.GetProperty("picture").Value;
var photo = uComponents.Core.uQuery.GetMedia(Convert.ToInt32(photoId));
var crop = MediaExtensions.GetImageCropperUrl(photo, "umbracoFile", "wide");
Pictures(crop);
}
}
}
我真的很感谢任何人可以提供的任何帮助...即使它让我知道如何在 Umbraco 中调试它。谢谢!
编辑:Umbraco 4.6.1 的版本
I'm new to Razor templates in Umbraco (and in general), but I prefer using it over XSLT files. However, I have run into a problem that I don't know how to solve. I am getting the following message:
An unknown error occured while rendering the following code:
System.NullReferenceException: Object reference not set to an instance of an object.
at RazorEngine.Dynamic.baeffbebc.Execute()
at RazorEngine.Templating.TemplateService.Parse[T](String template, T model, String name)
at umbraco.MacroEngines.RazorEngine.GetResult(String cacheIdentifier, String template, INode currentPage, String& result)
My macro looks like this:
@using System
@using uComponents.Core
@using uComponents.Core.uQueryExtensions
@using System.Linq
@using umbraco.NodeFactory
@helper NoPictures()
{
<li>Pictures coming soon!</li>
}
@helper Pictures(String crop)
{
<li><a rel="photos" href="@crop" title="test">
<img src="@crop" class="shadow hovershadow"></a></li>
}
@{
var n = Node.GetCurrent();
var pictures = n.GetProperty("pictures").Value;
if(pictures.Length <= 0)
{
NoPictures();
}
else
{
var pictureNodes = pictures.Split(',');
foreach (var pictureNode in pictureNodes)
{
var node = new Node(Convert.ToInt32(pictureNode));
var photoId = node.GetProperty("picture").Value;
var photo = uComponents.Core.uQuery.GetMedia(Convert.ToInt32(photoId));
var crop = MediaExtensions.GetImageCropperUrl(photo, "umbracoFile", "wide");
Pictures(crop);
}
}
}
I really appreciate any help that anyone can offer... even if it is giving me an idea how to debug this within Umbraco. Thanks!
Edit: The version of Umbraco 4.6.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我的最终代码是这样的:
代码没有太大变化,但显然之前运行宏时,我在某个地方出现了错误。无论我如何更改脚本,错误仍然存在。事实证明,Umbraco 的 Razor 缓存过于激进或存在错误,因此在对脚本进行更改时缓存并未失效。为了解决这个问题,我必须回收 IIS 中的应用程序池。现在一切正常。
Okay, my final code was this:
The code didn't change much, but apparently when running the macro before, I had an error somewhere. No matter what I did to change the script, the error persisted. It turns out that the Umbraco's Razor caching is too aggressive or has a bug, so the cache was not being invalidated when a change was made to the script. To work around it, I had to recycle the Application Pool in IIS. All is working now.