C# 写入linq查询sitemapnode
我想编写查询C# 写入linq查询sitemapnode,c#,c#-4.0,telerik,C#,C# 4.0,Telerik,我想编写查询smn.ParentNode.ChildNodes。如果ShowInNavigation值为false,我不想显示。Telerik站点地图节点有此联系人如何执行此操作 using System; using System.Web; using Telerik.Sitefinity.Web; using System.Linq; using System.Data; public partial class CustomTemplate_Navigation : System.Web
smn.ParentNode.ChildNodes
。如果ShowInNavigation值为false,我不想显示。Telerik站点地图节点有此联系人如何执行此操作
using System;
using System.Web;
using Telerik.Sitefinity.Web;
using System.Linq;
using System.Data;
public partial class CustomTemplate_Navigation : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SiteMapNode smn = SiteMapBase.GetCurrentProvider().CurrentNode;
while (smn.ParentNode != null)
{
if (smn.ParentNode.ParentNode == SiteMap.RootNode)
{
siteMapControl_verticaltree.DataSource = smn.ParentNode.ChildNodes;/*this line will be write query*/
siteMapControl_verticaltree.DataBind();
break;
}
smn = smn.ParentNode;
}
}
}
大概是这样的:
smn.ParentNode.ChildNodes.AsQueryable().Where(x => x.ShowInNavigation).ToList();
你可以做这样的事情:(你不仅要林奇菲,还需要演员阵容) (我在一个.NETMVC4项目中使用了它)
SiteMapNodeCollection coll=SiteMap.RootNode.ChildNodes;
IEnumerable节点=coll.Cast();
var query=从节点中的节点,其中Boolean.Parse(节点[“ShowInNavigation”])==真选择节点;
ChildNodes是ParentNode的属性。为什么要在查询中写入此项?若要查看显示导航节点值为false的某个节点,请告诉我们ChildNodeError 11的类型是什么?System.Web.SiteMapNodeCollection“”不包含“Where”的定义,并且没有扩展方法“Where”可以是“接受类型为”System.Web.SiteMapNodeCollection“”的第一个参数”在@temp中找到(您是否缺少using指令或程序集引用?)@temp-您必须使用AsQuerable()
将其Linqify,如上所示。
SiteMapNodeCollection coll = SiteMap.RootNode.ChildNodes;
IEnumerable<SiteMapNode> nodes = coll.Cast<SiteMapNode>();
var query = from node in nodes where Boolean.Parse(node["ShowInNavigation"]) == true select node;