如何使用动态数据/LINQTOSQL框架创建面包屑?

发布于 2024-08-19 19:46:25 字数 67 浏览 10 评论 0 原文

我需要一些关于如何创建动态面包屑控件的示例或想法,该控件将为由 LINQTOSQL 提供支持的动态日期框架动态生成面包屑

I need some EXAMPLES or IDEAS on how to created dynamic breadcrumb control which will dynamically generated breadcrumbs for Dynamic Date framework powered by LINQTOSQL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静赏你的温柔 2024-08-26 19:46:25

您可能需要三样东西:

  1. 数据库中的层次结构*
  2. 基于 StaticSiteMapProvider 读取层次结构
  3. A SiteMapPath 控件来显示面包屑。

* 当我想要为客户端站点提供类似的东西时,我进行了一些搜索,并决定将路径结构存储在数据库中将是最简单的 - 我已经给出了 之前的答案用于任意深度站点地图 - 请注意,如果您使用的是 SQL2008,可以使用新的 HierarchyId 数据类型来简化此操作。

话虽如此,如果您有类别和产品之类的内容,您可能可以在数据库中使用更简单的系统。

我需要创建来解决这个问题的关键函数如下:

/// <summary>
/// Gets this SiteMaps children.
/// </summary>
/// <value>The children.</value>
public List<SiteMap> Children {
  get {
    if (null == m_Children && !m_AttemptedToLoadChildren) {
      m_AttemptedToLoadChildren = true;

      m_Children = ctx.GetSiteMapChildrenByPath(_Path, 1).ToList();

      // Sorts ascending.
      m_Children.Sort(( sm1, sm2 ) => sm1.SortOrder.CompareTo(sm2.SortOrder));
      // CMS Sorts Descending, so reverse the list.
      m_Children.Reverse();
    }

    return m_Children;
  }
}

/// <summary>
/// Gets a value indicating whether this instance has any children.
/// </summary>
/// <value>
///  <c>true</c> if this instance has children; otherwise, <c>false</c>.
/// </value>
public bool HasChildren {
  get {
    if (null != Children && Children.Any()) {
      m_HasChildren = true;
    }

    return m_HasChildren;
  }
}

/// <summary>
/// Gets this SiteMaps parent.
/// </summary>
/// <value>The parent.</value>
public SiteMap Parent {
  get {
    if (null == m_Parent && null != _ParentId) {
      m_Parent = ctx.GetSiteMap(_ParentId);
    }

    return m_Parent;
  }
}

GetSiteMapGetSiteMapChildrenByPath 调用存储过程来构建层次结构,因为使用 LINQ 将其拉出将非常容易复杂的。

You'll probably need three things:

  1. A hierarchy structure in your database*
  2. A custom SiteMap provider based on the StaticSiteMapProvider to read the hierarchy
  3. A SiteMapPath control to display the Breadcrumb.

* I'd done some hunting around when I wanted something similar for a client site, and decided that storing the path structure in the database would be simplest - I've given the answer previously here for an arbitrary depth site map - note that if you're using SQL2008 you can use the new HierarchyId data type to make this a bit easier.

That being said, if you've got things like categories and products, you can probably get away with a simpler system in your database.

The key functions I needed to create to resolve this were things like:

/// <summary>
/// Gets this SiteMaps children.
/// </summary>
/// <value>The children.</value>
public List<SiteMap> Children {
  get {
    if (null == m_Children && !m_AttemptedToLoadChildren) {
      m_AttemptedToLoadChildren = true;

      m_Children = ctx.GetSiteMapChildrenByPath(_Path, 1).ToList();

      // Sorts ascending.
      m_Children.Sort(( sm1, sm2 ) => sm1.SortOrder.CompareTo(sm2.SortOrder));
      // CMS Sorts Descending, so reverse the list.
      m_Children.Reverse();
    }

    return m_Children;
  }
}

/// <summary>
/// Gets a value indicating whether this instance has any children.
/// </summary>
/// <value>
///  <c>true</c> if this instance has children; otherwise, <c>false</c>.
/// </value>
public bool HasChildren {
  get {
    if (null != Children && Children.Any()) {
      m_HasChildren = true;
    }

    return m_HasChildren;
  }
}

/// <summary>
/// Gets this SiteMaps parent.
/// </summary>
/// <value>The parent.</value>
public SiteMap Parent {
  get {
    if (null == m_Parent && null != _ParentId) {
      m_Parent = ctx.GetSiteMap(_ParentId);
    }

    return m_Parent;
  }
}

GetSiteMap and GetSiteMapChildrenByPath call into stored procs to build the hierarchy as pulling it out with LINQ was going to be quite complex.

多像笑话 2024-08-26 19:46:25

您好,您看过我的自定义 SitMapProvider 这里

这允许您从带有注释的元模型中获取结构以及非 DD 页面的单独站点地图文件。

Hi have you had a look at my custom SitMapProvider here

This allows you to get the structure from the metamodel with annotation and a seperate sitemap file for non DD pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文