orchard cms:如何将媒体选择器字段添加到自定义部件 [英] orchard cms: how to add media picker field to a custom part
问题描述
我的问题与问题/10369967/orchard-cms-how-to-add-media-picker-field-to-anew-module
我创建了一个新的内容部分,它有一个选择列表、一个文本框和......我想包括一个媒体选择器.
I've created a new content part, that has a select list, a text box and ... I want to include a media picker filed.
根据 Bertrand Le Roy 的建议,我已将此添加到内容部分:
I have added this to the content part with Bertrand Le Roy's suggestion of:
ContentDefinitionManager.AlterPartDefinition("Product",
builder => builder.WithField("ProductImage",
fieldBuilder => fieldBuilder
.OfType("MediaPickerField")
.WithDisplayName("Product Image")));
但是我不知道如何在我的自定义编辑器视图中显示这个
However I've no idea of how to show this in my custom editor View
我确信应该有像 @Display(Model.ProductImage) 这样简单的东西......但我已经遵循了 从 Orchard 文档中编写内容部分,并且我的编辑器视图中的模型不是动态的.
I'm sure there should be something easy like @Display(Model.ProductImage) ... but I've followed the writing a content part form the Orchard docs, and my model in my editor view is not dynamic.
因此,如果存在诸如 @Display(Model.ProductImage) 之类的魔法,我该如何将媒体选择器项添加到我的视图模型中?
So if such magic as @Display(Model.ProductImage) exists, how do I add the media picker item to my view model ?
更新
媒体选择器字段似乎显示在我添加此部分的内容类型上,而不是我想要的位置!我想显示/隐藏这个偏向于从选择列表中选择的值的字段,如何停止字段内容项的默认呈现并在我的自定义视图中呈现它?
The Media picker field seems to be showing on the content types where I add this part, just not where I want it! I want to show / hide this field biased on values selected form a select list, How can I stop the default rendering of the field Content Item and Render it in my custom view ?
更新 2
我已经在模型中添加了这个
I've added this in the model
public MediaPickerField MediaPicker
{
get{ return (MediaPickerField)((dynamic)ContentItem).HeaderPart.Image;}
}
这个到视图
@Html.Partial("EditorTemplates/Fields/MediaPicker.Edit", Model.MediaPicker)
这是placement.info
and this is the placement.info
<!-- MediaPicker -->
<Place Fields_MediaPicker_Edit="-"/>
现在通过cms端编辑看起来不错...但似乎没有将图像保存到数据库中!
Now it looks right on the editing via cms end... but dosen't seem to save the images to the database!
推荐答案
应该类似于 @Model.ContentItem.Product.ProductImage.Url
这篇关于orchard cms:如何将媒体选择器字段添加到自定义部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!