遍历this教程一切正常,但数据无法保存。 已创建表,编辑页面显示字段但未保存任何记录。单击保存按钮后,我收到以下消息:
您的Car ContentType已创建。
未找到
您要查找的页面不存在。
有什么想法吗?
型号:
public class CarPart : ContentPart<CarPartRecord> {
public string Name {
get { return Record.Name; }
set { Record.Name = value; }
}
public string Description {
get { return Record.Description; }
set { Record.Description = value; }
}
public bool IsPublished {
get { return Record.IsPublished; }
set { Record.IsPublished = value; }
}
}
public class CarPartRecord : ContentPartRecord {
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual bool IsPublished { get; set; }
}
处理程序:
public class CarPartHandler : ContentHandler {
public CarPartHandler(IRepository<CarPartRecord> repository) {
Filters.Add(StorageFilter.For(repository));
}
}
驱动器:
public class CarPartDriver : ContentPartDriver<CarPart> {
protected override string Prefix { get { return "Car"; } }
protected override DriverResult Editor(CarPart part, dynamic shapeHelper) {
return ContentShape("Parts_Car_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/Car", Model: part, Prefix: Prefix));
}
protected override DriverResult Editor(CarPart part, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}
迁移:
public int Create(){
SchemaBuilder.DropTable("CarPartRecord");
SchemaBuilder.CreateTable("CarPartRecord", table => table
.ContentPartRecord()
.Column<string>("Name",column => column.WithLength(50).NotNull().Unique())
.Column<string>("Description",column => column.WithLength(500))
.Column<bool>("IsPublished",column => column.WithDefault(true).NotNull()));
return 1;
}
public int UpdateFrom1() {
ContentDefinitionManager.AlterPartDefinition("CarPart",part => part.Attachable());
return 2;
}
错误:
Orchard.Exceptions.DefaultExceptionPolicy - 默认 - 捕获到意外的异常 HTTP ..... / OrchardLocal /管理/内容/制作/汽车 NHibernate.Exceptions.GenericADOException:无法执行批处理命令。[SQL:SQL不可用] ---&gt; System.Data.SqlClient.SqlException:无法将值NULL插入列'Name',表'OrchardDB.dbo.Mega_Car_CarPartRecord';列不允许空值。 INSERT失败。
NHibernate.AssertionFailure - 默认 - 发生AssertionFailure - 这可能表示NHibernate或您的自定义类型中存在错误。 HTTP .... / OrchardLocal /管理/内容/制作/汽车 NHibernate.AssertionFailure:Orchard.ContentManagement.Records.ContentTypeRecord条目中的null id(发生异常后不刷新会话)
Orchard.Web \模块\ M.Car \视图\ EditorTemplates \零件
@using System.Web.Mvc.Html
@model M.Car.Models.CarPart
<fieldset>
<legend>Car Fields</legend>
<div class="editor-label">@Html.LabelFor(x => x.Name)</div>
<div class="editor-field">
@Html.EditorFor(x => x.Name)
@Html.ValidationMessageFor(x => x.Name)
</div>
<div class="editor-label">@Html.LabelFor(x => x.Description)</div>
<div class="editor-field">
@Html.EditorFor(x => x.Description)
@Html.ValidationMessageFor(x => x.Description)
</div>
<div class="editor-label">@Html.LabelFor(x => x.IsPublished)</div>
<div class="editor-field">
@Html.EditorFor(x => x.IsPublished)
@Html.ValidationMessageFor(x => x.IsPublished)
</div>
</fieldset>