Created
January 11, 2019 09:31
-
-
Save AThraen/9bab89b6e5d00496c52174afd00d0a60 to your computer and use it in GitHub Desktop.
Custom Episerver Image On Page Edit solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Linq; | |
| using System.Web.Mvc; | |
| using EPiServer.Core; | |
| using EPiServer.Framework.DataAnnotations; | |
| using EPiServer.Framework.Web; | |
| using SmallExperiments.Business; | |
| using SmallExperiments.Models.Pages; | |
| using SmallExperiments.Models.ViewModels; | |
| using EPiServer.Web; | |
| using EPiServer.Web.Mvc; | |
| using EPiServer; | |
| using EPiServer.Framework.Web.Mvc; | |
| using SmallExperiments.Models.Media; | |
| using EPiServer.Shell; | |
| using EPiServer.Web.Routing; | |
| using EPiServer.ServiceLocation; | |
| using EPiServer.Cms.Shell; | |
| namespace SmallExperiments.Controllers | |
| { | |
| [TemplateDescriptor( | |
| Inherited = true, | |
| TemplateTypeCategory = TemplateTypeCategories.MvcController, | |
| Tags = new[] { RenderingTags.Edit }, | |
| AvailableWithoutTag = false,ModelType = typeof(ImageData))] | |
| [VisitorGroupImpersonation] | |
| [RequireClientResources] | |
| public class ImagePreviewController : ActionControllerBase, IRenderTemplate<ImageData>, IRenderTemplate | |
| { | |
| private readonly UrlResolver _urlResolver; | |
| private readonly TemplateResolver _templateResolver; | |
| public ImagePreviewController() | |
| : this(ServiceLocator.Current.GetInstance<UrlResolver>(), ServiceLocator.Current.GetInstance<TemplateResolver>()) | |
| { | |
| } | |
| public ImagePreviewController(UrlResolver urlResolver, TemplateResolver templateResolver) | |
| { | |
| this._urlResolver = urlResolver; | |
| this._templateResolver = templateResolver; | |
| } | |
| public ActionResult Index(IContent currentContent) | |
| { | |
| var url = (currentContent as IContentImage).PreviewUrl(_urlResolver, _templateResolver); | |
| ViewBag.ImageUrl = url; | |
| return View(currentContent); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @using SmallExperiments | |
| @model SmallExperiments.Models.Media.ImageFile | |
| @{ | |
| Layout = null; | |
| } | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title></title> | |
| </head> | |
| <body> | |
| <div> | |
| <h1>@Html.PropertyFor(m => m.Name)</h1> | |
| <img src="@ViewBag.ImageUrl" width="600" /> | |
| @Html.PropertyFor(m => m.Copyright) | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment