Orchardcms ContentManager.Create不执行任何操作

Orchardcms ContentManager.Create不执行任何操作,orchardcms,Orchardcms,我试图在Orchard中构建一个服务,允许我通过页面上的自定义表单创建内容。该服务和内容类型定义在我看来很好,但不知何故,即使我在Orchard日志文件中没有收到任何错误或其他迹象,使用IContentManager创建新内容对我来说毫无帮助 涉及的部分 接受表单值的控制器 [HttpPost] public ActionResult Create(CreateSopViewModel viewModel) { if(!ModelState.IsValid) {

我试图在Orchard中构建一个服务,允许我通过页面上的自定义表单创建内容。该服务和内容类型定义在我看来很好,但不知何故,即使我在Orchard日志文件中没有收到任何错误或其他迹象,使用IContentManager创建新内容对我来说毫无帮助

涉及的部分 接受表单值的控制器

[HttpPost]
public ActionResult Create(CreateSopViewModel viewModel)
{
    if(!ModelState.IsValid)
    {
        var shape = _shape.CreateContent();
        shape.Header = _shape.Parts_Title(Title: "New item");

        // Add the original fields to the shape.
        shape.Title = viewModel.Title;
        shape.Description = viewModel.Description;
        shape.InitialComments = viewModel.InitialComments;

        return new ShapeResult(this, shape);
    }

    // Store the new procedure in the database
    _service.CreateContentItem(
        viewModel.Title,viewModel.Description,viewModel.InitialComments);

    // Redirect the user back to the homepage.
    return Redirect("~/");
}
包含CreateContentItem方法的服务:

public void CreateContentItem(string title, string description, string initialComments)
{
    // Initialize a new content item based on the SOP type
    var customPart = _services.ContentManager.New<MyCustomPart>("CustomContentType");

    customPart.Description = description;
    customPart.Identifier = BuildIdentifier(title);
    customPart.ContentItem.As<TitlePart>().Title = title;

    _services.ContentManager.Create(customPart.ContentItem);
}
public void CreateContentItem(字符串标题、字符串描述、字符串初始注释)
{
//根据SOP类型初始化新内容项
var customPart=_services.ContentManager.New(“CustomContentType”);
customPart.Description=说明;
customPart.Identifier=BuildIdentifier(标题);
customPart.ContentItem.As().Title=标题;
_services.ContentManager.Create(customPart.ContentItem);
}
内容部分+记录

public class MyCustomPart: ContentPart<MyCustomPartRecord>
{
    [Required]
    public string Identifier
    {
        get { return Record.Identifier; }
        set { Record.Identifier = value; }
    }

    [Required]
    public string Description
    {
        get { return Record.Description; }
        set { Record.Description = value; }
    }
}

public class MyCustomPartRecord: ContentPartRecord
{
    public virtual string Identifier { get; set; }

    public virtual string Description { get; set; }
}
公共类MyCustomPart:ContentPart
{
[必需]
公共字符串标识符
{
获取{return Record.Identifier;}
设置{Record.Identifier=value;}
}
[必需]
公共字符串描述
{
获取{return Record.Description;}
设置{Record.Description=value;}
}
}
公共类MyCustomPartRecord:ContentPartRecord
{
公共虚拟字符串标识符{get;set;}
公共虚拟字符串描述{get;set;}
}
迁移

SchemaBuilder.CreateTable(typeof(MyCustomPartRecord).Name, table => table
    .ContentPartRecord()
    .Column<string>("Description")
    .Column<string>("Identifier"));

ContentDefinitionManager.AlterPartDefinition("StandardOperationalProcedurePart", builder => builder
        .Attachable(true));

ContentDefinitionManager.AlterTypeDefinition("CustomContentType", builder => builder
    .DisplayedAs("Custom Content Type")
    .WithPart("TitlePart")
    .WithPart("MyCustomPart")
    .Creatable(true));
schemabilder.CreateTable(typeof(MyCustomPartRecord).Name,table=>table
.ContentPartRecord()
.栏(“说明”)
。栏(“标识符”);
ContentDefinitionManager.AlterPartDefinition(“StandardOperationalProcedurePart”,builder=>builder
.可附加(真实));
ContentDefinitionManager.AlterTypeDefinition(“CustomContentType”,builder=>builder
.DisplayedAs(“自定义内容类型”)
.附部分(“标题部分”)
.WithPart(“我的客户部分”)
.可创建(真实));
问题: 同样,我没有收到任何错误,日志中和VisualStudio中都没有。但是,我的新内容项没有被创建,或者至少,我在网站的“内容”下的“管理”部分看不到它


发生了什么以及如何调试此行为?

我遇到了类似的问题,当我使用重载的
Create
方法,使用
VersionOptions
枚举值时,问题得到了解决:

content.Create(customPart.ContentItem,VersionOptions.Published)


即使内容项不可创建,这也应该有效,因为我的内容项不可创建。

我有一个类似的问题,当我使用重载的
Create
方法,使用
VersionOptions
枚举值时,问题得到了解决:

content.Create(customPart.ContentItem,VersionOptions.Published)


即使内容项不可创建,这也应该有效,因为我的内容项不可创建。

我也有类似的问题。在我的例子中,这个项目最终出现了,但不是马上出现

我的解决方案是:

_contentManager.Flush();

我也有类似的问题。在我的例子中,这个项目最终出现了,但不是马上出现

我的解决方案是:

_contentManager.Flush();

我遇到了这个问题,在我的例子中,我实际上在数据库中有一个错误(试图将100多个字符放入一个只能容纳100个字符的字段!)

我发现我得到的错误(Orchard.Indexing.Models.IndexingTaskRecord条目中的null id(发生异常后不要刷新会话))实际上掩盖了问题。我不得不在日志中寻找真正的问题


总之,我的建议是,如果您看到contentmanager.create似乎什么都没做,并且任何错误似乎都没有帮助,请仔细检查日志。它们可以在主Orchard.Web项目的appdata文件夹的logs子文件夹中找到。因为正如我在过去48小时里发现的那样,答案往往就在那里。

我遇到了这个问题,在我的例子中,我实际上在数据库中出现了一个错误(试图将100多个字符放入一个只能容纳100个字符的字段!)

我发现我得到的错误(Orchard.Indexing.Models.IndexingTaskRecord条目中的null id(发生异常后不要刷新会话))实际上掩盖了问题。我不得不在日志中寻找真正的问题


总之,我的建议是,如果您看到contentmanager.create似乎什么都没做,并且任何错误似乎都没有帮助,请仔细检查日志。它们可以在主Orchard.Web项目的appdata文件夹的logs子文件夹中找到。因为正如我在过去48小时内所发现的,答案通常是存在的。

处理程序中是否也有用于记录的StorageFilter?是的,我有,打开日志记录后,我发现实际上它确实会将记录插入数据库。更奇怪的是,当我使用查询向ContentManager请求内容类型时,我得到了返回的项目。然而,管理员界面没有显示它,这让我很困扰。内容类型不可创建可能会导致这种情况,但我看到你有它,所以我没有进一步的想法。不幸的是…你在处理程序中也有一个用于记录的StorageFilter吗?是的,在打开日志之后,我发现事实上它确实将记录插入到数据库中。更奇怪的是,当我使用查询向ContentManager请求内容类型时,我得到了返回的项目。然而,管理UI没有显示它,这让我很困扰。内容类型不可创建可能会导致这种情况,但我看到你有它,所以我没有进一步的想法。不幸的是…只有当你需要相同HTTP请求中的新内容时,此解决方案才有用。我没有,但这仍然是一个有用的建议。我找不到
Flush
!?只有在同一HTTP请求中需要新内容时,此解决方案才有用。我没有,但这仍然是一个有用的建议。我找不到
Flush
!?