November Happy Hour will be moved to Thursday December 5th.

File preview in MVC

Vote:
 

Is it possible to build a custom preview view for files? The customer wants to see metadata without having to go to forms mode.

I’ve tried with this code http://joelabrahamsson.com/pattern-for-episerver-block-preview-mvc-controller/, and then I just replaced BlockData with ImageData. But it doesn’t work, the response is shown inside an image-tag. Is there any way to override the default view of image files? And is it possible to do it for other file types as well, not just images?

#86087
May 13, 2014 17:21
Vote:
 

In the returnView you could add a path to your own View and on that add your own html for what you wish to show.

returnView("pathToYourView");

If you want it wo work for all filetypes I would change the controller to hook on MediaData or your own base class for media (if you have one) and then check what type and return diffrent views depending on what type it is. Something like this:
namespace MySite
{
    [TemplateDescriptor(
        Inherited = true,
        TemplateTypeCategory = TemplateTypeCategories.MvcController,
        Tags = new [] { RenderingTags.Preview },
        AvailableWithoutTag = false)]
    public class PreviewController : Controller, IRenderTemplate<MediaData>
    {
        public ActionResult Index(IContent currentContent)
        {
			if(currentContent is ImageData)
				return View("~/Views/ImageData/Index.cshtml");
			if(currentContent is DocumentData)
				return View("~/Views/ImageData/Index.cshtml");
			return View("~/Views/MediaData/Index.cshtml");
        }
    }
}
    
#86109
May 14, 2014 10:19
Vote:
 

I can get the controller to work for ImageData so that it returns a view. But episerver dosen't show the view, it links to it in a img-tag. So all I get is a broken image.

The controller never runs if i change the type to MediaData.

#86123
May 14, 2014 11:36
Vote:
 

This should work:

      [TemplateDescriptor(
        Inherited = true,
        TemplateTypeCategory = TemplateTypeCategories.MvcController,
        Tags = new [] { RenderingTags.Edit },
        AvailableWithoutTag = false)]
    public class PreviewController : Controller, IRenderTemplate<ImageData>
    {
          public ActionResult Index(IContentMedia currentContent)
        {
            return View(currentContent);
        }
    }

    

#86124
May 14, 2014 11:42
Vote:
 
@model  ImageData

@PropertyFor(x => x.<MetadataPropHere>)

    

Try adding this to your ImageData view.

By default EpiServer will try and render you ImageData object as a Image so it will become a img tag.

Extra info:

You could override how EPi renders by adding a view in Views/Shared/DisplayTemplates/Image.cshtml.. But I don't think this is what you want as this will override the redering for all places on the site.

#86125
May 14, 2014 11:51
Vote:
 

Changing the rendering tag to edit instead of preview seems to have done the trick.

#86128
May 14, 2014 11:59
Vote:
 

sweet

#86129
May 14, 2014 12:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.