在 Orchard 摘要视图中,我显示的内容项可以是页面、博客文章或投影。
我为所有这些类型附加了一个媒体选择器字段并将其命名为图片。
我目前正在使用这段可怕的代码从内容项中访问媒体选择器:
if (contentItem != null)
{
    try
    {
        mediaPicker = (MediaLibraryPickerField) contentItem.Blog.Picture;
    }
    catch (Exception e) {}
    if (mediaPicker == null)
    {
        try
        {
            mediaPicker = (MediaLibraryPickerField)
                            contentItem.Page.Picture;
        }
        catch (Exception e) {}
    }
    if(mediaPicker == null)
    {
        try
        {
            mediaPicker = (MediaLibraryPickerField) contentItem.ProjectionPage.Picture;
        }
        catch (Exception e) {}
    }
}
一定会有更好的办法?