2
votes

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
Now you've moved the goalpost ;) It seems like what you are trying to do is very different from what your original question suggested. It seems like you are trying to re-use the media picker field in a very customized situation. In other words, re-use its UI but not really the field itself. The media picker extension to TinyMCE may be a better starting point for your custom part's code.Bertrand Le Roy
I see it as adding definition during research! ... but I see your point. I was thinking there must be a module that dose this somewhere, and couldn't think of which one. thanks I'll have a look at TinyMCEAxe

1 Answers

3
votes

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