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");
}
}
}
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.
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);
}
}
@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.
Changing the rendering tag to edit instead of preview seems to have done the trick.
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?