gpt4 book ai didi

orchardcms - Orchard 内容类型为空

转载 作者:行者123 更新时间:2023-12-02 20:26:17 26 4
gpt4 key购买 nike

我是 Orchard 模块开发的新手。我创建了一个模块。当我尝试保存数据时。我在保存数据之前使用此代码

    public ActionResult Create(FormCollection input)
{
var product = contentManager.New<ProductPart>("Product");
product.EmployeeName = input["EmployeeName"];
product.EmployeeFathersName = input["EmployeeFathersName"];
product.DOB = Convert.ToDateTime(input["DOB"]);
product.Email = input["Email"];
product.Address = input["Address"];
product.JoiningDate = Convert.ToDateTime(input["JoiningDate"]);

if (!ModelState.IsValid)
{
return View(product);
}

contentManager.Create(product);

return RedirectToAction("Index");
}

我在模型中使用这个类

public class ProductRecord:ContentPartRecord
{
public virtual string EmployeeName { get; set; }

public virtual string EmployeeFathersName { get; set; }
public virtual DateTime DOB { get; set; }
public virtual string Email { get; set; }
public virtual string Address { get; set; }
public virtual DateTime JoiningDate { get; set; }
}

public class ProductPart : ContentPart<ProductRecord>
{
/*
public int Id
{
get { return Record.Id; }
set{Record.Id = value;}
}
*/

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

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

[Required]
public DateTime DOB
{
get { return Record.DOB; }
set { Record.DOB = value; }
}
[Required]
public string Email
{
get { return Record.Email; }
set { Record.Email = value; }
}
[Required]
public string Address
{
get { return Record.Address; }
set { Record.Address = value; }
}
[Required]
public DateTime JoiningDate
{
get { return Record.JoiningDate;}
set { Record.JoiningDate = value; }
}

}

我使用内容类型“Product”,但是当它在下面的方法中进入 Orchard ContentCreateExtension时

   public static T New<T>(this IContentManager manager, string contentType) where T : class, IContent {
var contentItem = manager.New(contentType);
if (contentItem == null)
return null;

var part = contentItem.Get<T>();
if (part == null)
throw new InvalidCastException();

return part;
}

这里我面临 var 部分为 null,这意味着它的内容部分为 null。
请帮助我......

最佳答案

您设置了迁移类吗?

public class Migrations : DataMigrationImpl {

public int Create() {
SchemaBuilder.CreateTable("ProductRecord",
table => table
.ContentPartRecord()
.COLUMNS NEED TO BE SPECIFIED
);

ContentDefinitionManager.AlterTypeDefinition("Forum",
cfg => cfg
.WithPart("ProductPart")
.WithPart("CommonPart")
);

您还设置了存储库吗?

public class ProductPartHandler : ContentHandler {
public ProductPartHandler(IRepository<ProductPartRecord> repository) {
Filters.Add(StorageFilter.For(repository));
}

关于orchardcms - Orchard 内容类型为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7006932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com