Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 围绕顶部项目创建包装div_C#_Linq_Razor_Umbraco - Fatal编程技术网

C# 围绕顶部项目创建包装div

C# 围绕顶部项目创建包装div,c#,linq,razor,umbraco,C#,Linq,Razor,Umbraco,我有一个脚本,其中列出了我所有的新闻项目。 现在我的输出是: <section class="news-list"> <article class="news-item top-news"> <a href="/nyheder/dbu-nyhed-4/">DBU Nyhed 4 (Topnyhed)</a> </article>

我有一个脚本,其中列出了我所有的新闻项目。 现在我的输出是:

<section class="news-list">            

            <article class="news-item top-news">
                <a href="/nyheder/dbu-nyhed-4/">DBU Nyhed 4 (Topnyhed)</a>
            </article>
            <article class="news-item top-news">
                <a href="/nyheder/dbu-nyhed/">DBU Nyhed (Topnyhed)</a>
            </article>
            <article class="news-item">
                <a href="/nyheder/dbu-nyhed-3/">DBU Nyhed 3</a>
            </article>
            <article class="news-item">
                <a href="/nyheder/dbu-nyhed-2/">DBU Nyhed 2</a>
            </article>

</section>

我想做的是:

  • 围绕所有“热门新闻”文章项创建一个包装div
代码如下所示:

@if (CurrentPage.Children.Where("Visible").Any())
{
<section class="news-list">            
    @* For each child page under the root node, where the property umbracoNaviHide is not True *@
    @foreach (var childPage in CurrentPage.Children.Where("Visible").OrderBy("topNews desc, CreateDate desc"))
    {
        var isTopNews = childPage.topNews;
        if (isTopNews)
        {
            <article class="news-item top-news">
                <a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
            </article>
        }
        else
        {
            <article class="news-item">
                <a href="@childPage.Url">@childPage.Name</a>
            </article>
        }
    }

</section>
}
@if(CurrentPage.Children.Where(“可见”).Any())
{
@*对于根节点下的每个子页,其中属性umbracanavihide不是True*@
@foreach(CurrentPage.Children.Where(“可见”).OrderBy(“topNews desc,CreateDate desc”)中的var childPage)
{
var isTopNews=childPage.topNews;
如果(isTopNews)
{
}
其他的
{
}
}
}

您应该将列表一分为二:

@if (CurrentPage.Children.Where("Visible").Any())
{
<section class="news-list">            
    @* For each child page under the root node, where the property umbracoNaviHide is not True *@
    @foreach (var childPage in CurrentPage.Children.Where("Visible").Where("topNews").OrderBy("CreateDate desc"))
    {
        <article class="news-item top-news">
            <a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
        </article>
    }

    @foreach (var childPage in CurrentPage.Children.Where("Visible").Where("not topNews").OrderBy("CreateDate desc"))
    {
        <article class="news-item">
            <a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
        </article>
    }
</section>
}
@if(CurrentPage.Children.Where(“可见”).Any())
{
@*对于根节点下的每个子页,其中属性umbracanavihide不是True*@
@foreach(CurrentPage.Children.Where(“可见”).Where(“topNews”).OrderBy(“CreateDate desc”))
{
}
@foreach(CurrentPage.Children.Where(“可见”).Where(“非热门新闻”).OrderBy(“CreateDate desc”))
{
}
}

然后将div围绕您需要的内容进行包装。

然后创建,问题是什么?为什么不创建两个列表,一个有热门新闻项目,一个没有,这样您就可以创建两个foreach循环?啊,从来没有想过这个解决方案:)Thx mate:)