【问题标题】:Umbraco razor macro DynamicPublishedContentList does not contain a definition forUmbraco razor 宏 DynamicPublishedContentList 不包含对
【发布时间】:2015-07-07 01:24:40
【问题描述】:

我的 umbraco 视图为一个可以正常工作的宏生成了以下代码:

@* Helper method to travers through all descendants *@
@helper Traverse(dynamic node)
{
    @* Update the level to reflect how deep you want the sitemap to go *@
    var maxLevelForSitemap = 5;

    @* Select visible children *@
    var selection = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);

    @* If any items are returned, render a list *@
    if (selection.Any())
    {
        <ul>
            @foreach (var page in selection)
            {
                <li class="level-@page.Level @(page.IsAncestorOrSelf(CurrentPage) ? "on" : null)">
                    @if (page.isNotNavigable == true)
                    {
                        <span>
                            <cite class="arrow"></cite>@page.Name
                        </span>
                    }
                    //if next line fails, add before the if below: page.HasProperty("pageRedirectTarget")
                    else if (page.HasValue("pageRedirectTarget"))
                    {
                        var redirectPage = Umbraco.Content(page.pageRedirectTarget);
                        <a href="@redirectPage.Url.Substring(0, redirectPage.Url.Length - 1)@page.pageRedirectComplement">
                            <cite class="arrow"></cite>@page.Name
                        </a>
                    }
                    else
                    {
                        <a href="@page.Url">
                            <cite class="arrow"></cite>@page.Name
                        </a>
                    }

                    @* Run the traverse helper again for any child pages *@
                    @Traverse(page)
                </li>
            }
        </ul>
    }
}

当我添加另一个 dll(在 3.5 框架中编译)并且 selection.Any() 停止工作时,会出现问题,而是给出错误消息“不包含 Any() 的定义” .

我知道 dynamic 不支持扩展方法,但为什么它在我不添加引用的情况下工作并给出错误?

谁能帮帮我?

谢谢。

【问题讨论】:

  • 另一个有问题的 dll 是什么?另外,我建议使用 IPublishedContent 而不是动态的。例如遍历(IPublishedContent 节点)
  • 它是“定制的”butin .net 3.5 与 sharepoint 2007 兼容
  • 只是想知道,你试过“selection.Length() > 0”
  • 正如 MrVentzi 上面建议的那样...尝试 .Length() 或 .Count() 看看你会得到什么。

标签: c# razor model-view-controller umbraco


【解决方案1】:

不完全是一个答案,但评论太长了,希望它对您的故障排除有所帮助。
检查 bin 目录中的以下 .dll,如果您的项目不需要它们,请删除它们。一次删除一个,然后重新测试,看看是否可以确定。

EntityFramework.SqlServer.dll
WebGrease.dll(删除并更新到 最新)
DotNetOAuth.dll

此信息来自 Umbraco 论坛,尤其是下面链接的两个帖子。

https://our.umbraco.org/forum/developers/razor/45308-umbracoMacroEnginesDynamicNodeList-does-not-contain-a-definition-for-Random

https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53022-UmbracoWebModelsDynamicPublishedContentList-does-not-contain-a-definition-for-Any

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 2012-05-28
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    相关资源
    最近更新 更多