我的模块中有两种设置。
现在我有一个控制器,我想要两个设置。
在控制器中,我可以获得如下全局设置:
var globalSettings = Services.WorkContext.CurrentSite.As<Interspire_MailingSettingsPart>();
但我怎样才能获得本地设置?
两位处理程序:
全局
public class MailingSettingsHandler:ContentHandler { public MailingSettingsHandler(IRepository repository) { T = NullLocalizer.Instance; Filters.Add(new ActivatingFilter(&#34; Site&#34;)); Filters.Add(new TemplateFilterForPart(&#34; Nastavitve&#34;,&#34; Parts / MailingSettings&#34;,&#34; Interspire&#34;)); Filters.Add(StorageFilter.For(储存库)); }
public Localizer T { get; set; }
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
if (context.ContentItem.ContentType != "Site")
return;
base.GetItemMetadata(context);
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Interspire")));
}
}
本地
公共类MailingHandler:ContentHandler { public MailingHandler(IRepository存储库) { Filters.Add(StorageFilter.For(储存库)); } }
编辑: 添加驱动程序,如果它可以提供帮助:
public class MailingDriver : ContentPartDriver<Interspire_MailingPart>
{
private readonly IOrchardServices _services;
public MailingDriver(INotifier notifier, IOrchardServices services)
{
_services = services;
}
protected override DriverResult Display(Interspire_MailingPart part, string displayType, dynamic shapeHelper)
{
var mailingSettings = _services.WorkContext.CurrentSite.As<Interspire_MailingSettingsPart>();
return ContentShape("Parts_Mailing",
() => shapeHelper.Parts_Mailing(
Url: mailingSettings.Url,
SubscribeFormID: part.SubscribeFormID
));
}
//GET
protected override DriverResult Editor(Interspire_MailingPart part, dynamic shapeHelper)
{
return ContentShape("Parts_Mailing_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/Mailing",
Model: part,
Prefix: Prefix));
_services.WorkContext.CurrentSite.As<Interspire_MailingPart>() = part;
}
//POST
protected override DriverResult Editor(Interspire_MailingPart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}