【问题标题】:Creating a SiteSettings Content Part in Orchard在 Orchard 中创建 SiteSettings 内容部分
【发布时间】:2014-09-05 17:06:09
【问题描述】:

我正在尝试为网站设置创建一个白名单部分,以允许管理员用户输入被视为“白名单”的 url 列表。不过,我在将这些信息存储在数据库中时遇到了问题。当使用属于数据库的信息创建新的内容类型时,您可以使用以下内容:

public class ShareBarSettingsPart : ContentPart<ShareBarSettingsPartRecord> {
    public string AddThisAccount {
        get { return Record.AddThisAccount; }
        set { Record.AddThisAccount = value; }
        }
    }

在数据库中设置 AddThisAccount 的值。我的问题是我需要数据库中的 url 列表,而不仅仅是单个项目。我尝试了以下方法,但它给了我一个错误:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;

namespace Speedbump.Models
{
    public class SpeedBumpSettingsRecord : ContentPartRecord
    {
        public virtual List<string> whiteList { get; set; }
    }

    public class SpeedBumpSettingsPart : ContentPart<SpeedBumpSettingsRecord>
    {
        public List<string> whiteList
        {
            get { return Record.whiteList; }
            set { Record.whiteList.Add(value); } //I need to be able to add a single record to the list here
        }
    }
}

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: database list settings orchardcms record


    【解决方案1】:

    List&lt;string&gt; 不支持作为记录属性类型。然而,这并不重要,因为您永远不应该将记录用于站点设置部分。请改用StoreRetrieve。任何现有的设置部分都会给你一个例子。

    【讨论】:

    • 为什么 Orchard 的网站说要使用记录? docs.orchardproject.net/Documentation/Adding-custom-settings 看起来很奇怪。我将查看电子邮件模块并以这种方式实现我的。感谢您的帮助。
    • 我的白名单设置正常工作,我可以保存设置,但如何检索白名单中的内容?我尝试了以下方法,但它不起作用: string whitelist = WorkContext.CurrentSite.As;
    • Orchard 文档说要使用记录,因为它已经过时并且需要更新。你快到了:As 的结果就是部分。您现在需要获取其WhiteList 属性。旁注:您的属性名称不遵守 .NET 命名约定。他们应该是驼峰式的。
    • 我收到一条错误消息,指出无法找到命名空间 WhiteListSettingsPart。有任何想法吗?字符串 WhiteList = _contextAccessor.GetContext().CurrentSite.As.WhiteList;
    • 我正在尝试访问单独模块中的新设置。我添加了一个参考并使用 Whitelist.Models;到我试图访问信息的模块,但现在我收到一条错误消息:Orchard.ContentManagement.ContentExtensions.As(Orchard.ContentManagement.IContent) 是一种在给定上下文中无效的方法
    猜你喜欢
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    相关资源
    最近更新 更多