다른 무엇보다도 이미지를 포함하는 콘텐츠 형식을 프로그래밍 방식으로 만들고 싶습니다. 이를 수행하는 확실한 방법은 MediaLibraryPickerField
을 사용하는 것입니다.사용자 지정 콘텐츠 형식의 MediaLibraryPickerField가 표시되지 않습니다.
내 질문 this one 매우 유사하지만, 불행하게도 그것은
내 문제는 내가 필드가 나타나기를 얻을 수있는 해답을 제공하지 않습니다. 나는 문서와 다른 온라인 리콜을 통해 파고 있었지만, 지금까지는 운이 없다. 나는 누군가가 내가 무엇을 놓쳤는지를 알 수 있기를 희망하면서 모든 코드를 여기에 올릴 것이다. 나는 배우기 때문에 이상한 일을하는 경우 주저하지 말고 지적하십시오.
내 콘텐츠 형식으로 구성해야합니다
- 제목
- 바디
- 설명
- 이미지
Migration.cs :
SchemaBuilder.CreateTable("MyTypePartRecord",
table => table
.ContentPartRecord()
.Column<string>("Description", c => c.Unlimited())
);
ContentDefinitionManager.AlterPartDefinition(
"MyTypePart", builder => builder
.WithDescription("Turns content types into a MyType.")
.WithField("Image", f => f.OfType(typeof(MediaLibraryPickerField).ToString()))
.Attachable()
);
ContentDefinitionManager.AlterTypeDefinition(
"MyType",cfg => cfg
.WithPart("CommonPart")
.WithPart("MyTypePart")
.WithPart("TitlePart")
.WithPart("BodyPart")
.Creatable()
);
모델/MyTypePart.cs :
public class MyTypePart : ContentPart<MyTypePartRecord>
{
public string Description
{
get { return Record.Description; }
set { Record.Description = value; }
}
}
모델/MyTypePartRecord.cs :
public class MyTypePartRecord : ContentPartRecord
{
[StringLengthMax]
public virtual string Description { get; set; }
}
모델/MyTypePartRecordHandler.cs :
public class MyTypePartRecordHandler : ContentHandler
{
public MyTypePartRecordHandler(IRepository<MyTypePartRecord> repository) {
Filters.Add(StorageFilter.For(repository));
}
}
드라이버/MyTypeDriver.cs
public class MyTypeDriver : ContentPartDriver<MyTypePart> {
public MyTypeDriver() {
}
// GET
protected override DriverResult Display(MyTypePart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_MyType",
()=> shapeHelper.Parts_MyType(
Description: part.Description
));
}
// GET
protected override DriverResult Editor(MyTypePart part, dynamic shapeHelper)
{
return ContentShape("Parts_MyType_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/MyType",
Model: part,
Prefix: Prefix));
}
// POST
protected override DriverResult Editor(MyTypePart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}
조회수 /EditorTemplates/Parts/MyType.cshtml :
@model MySolution.Models.MyType
<fieldset>
<div class="editor-label">@T("Description"):</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Description)
@Html.ValidationMessageFor(m => m.Description)
</div>
</fieldset>
조회수/부품/MyType.cshtml :
@using MySolution.Models
<div>Description: @Model.Description</div>
placement.info :
<Placement>
<Place Parts_MyType="Content:1"/>
<Place Parts_MyType_Edit="Content:7.5"/>
</Placement>
UPDATE
로 추천, 변경됨 MyTypePart
을모듈 전체에 10 개. 이제 콘텐츠 정의에서 Image
필드가 콘텐츠 형식의 MyTypePart 부분이 아닌 콘텐츠 형식에 직접 표시됩니다. 그래도 새 항목을 만들 때 필드가 표시되지 않습니다.
콘텐츠 정의로 이동하면 필드가 나타 납니까? 문제는 유형과 이름이 같은 부분에 필드를 추가하는 대신 파트에 필드를 추가 한 것입니다. –
컨텐트 유형 또는 컨텐트 정의에서 컨텐트 정의를 검사 할 때 필드를 볼 수 있지만 새 항목을 만들려고 할 때 제목, 본문 및 설명 필드 만 표시됩니다. 그래서 그것은 나에게 Content Type과 Part가 올바르게 생성 된 것처럼 보이지만 나는 다른 뭔가를 잘못하고있다. – Rik
부품의 이름을 유형과 일치하도록 변경하거나 유형과 이름이 같은 다른 부품에 필드를 추가해도 문제가 해결되지 않습니다. – Rik