orchard cms: how to add media picker field to a custom part

眉间皱痕 提交于 2019-12-06 10:31:31

问题


My question is simmalar to questions/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.

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

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.

So if such magic as @Display(Model.ProductImage) exists, how do I add the media picker item to my view model ?

Update

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 ?

Update 2

I've added this in the model

 public MediaPickerField MediaPicker
        {
            get{ return (MediaPickerField)((dynamic)ContentItem).HeaderPart.Image;}

        }

this to the view

@Html.Partial("EditorTemplates/Fields/MediaPicker.Edit", Model.MediaPicker)

and this is the placement.info

 <!-- MediaPicker -->
    <Place Fields_MediaPicker_Edit="-"/>

Now it looks right on the editing via cms end... but dosen't seem to save the images to the database!


回答1:


Should be something like @Model.ContentItem.Product.ProductImage.Url



来源:https://stackoverflow.com/questions/12387698/orchard-cms-how-to-add-media-picker-field-to-a-custom-part

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!