Last active
January 3, 2020 00:22
-
-
Save VesselinVassilev/31b159a1985f272e85b4ff167e59c8d8 to your computer and use it in GitHub Desktop.
Image Selector - Sitefinity MVC
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
| @Html.Raw(ViewBag.RichText) | |
| @if (ViewBag.ImageId != null) | |
| { | |
| if (Guid.TryParse(ViewBag.ImageId.ToString(), out Guid imgId)) | |
| { | |
| var image = Telerik.Sitefinity.App.WorkWith().Image(imgId).Get(); | |
| if (image != null) | |
| { | |
| <div class="form-group"> | |
| <label>Selected Image</label> | |
| <img src="@image.MediaUrl" /> | |
| </div> | |
| } | |
| } | |
| } |
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 SitefinityWebApp.Custom.Helpers; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Linq; | |
| using System.Web.Mvc; | |
| using Telerik.Sitefinity.DynamicModules; | |
| using Telerik.Sitefinity.Mvc; | |
| using Telerik.Sitefinity.Web.UI; | |
| namespace SitefinityWebApp.Mvc.Controllers | |
| { | |
| [ControllerToolboxItem(Name = "DemoController", Title = "Demo Widget", SectionName = "Admin Widgets", CssClass = "sfMvcIcn")] | |
| [IndexRenderMode(IndexRenderModes.NoOutput)] | |
| public class DemoController : Controller | |
| { | |
| /// <summary> | |
| /// To use the image selector | |
| /// </summary> | |
| public Guid ImageId { get; set; } | |
| /// <summary> | |
| /// For this property we will create a rich text editor designer | |
| /// </summary> | |
| public string RichText { get; set; } | |
| [HttpGet] | |
| public ActionResult Index() | |
| { | |
| ViewBag.ImageId = this.ImageId; | |
| ViewBag.RichText = this.RichText; | |
| return View("Default"); | |
| } | |
| protected override void HandleUnknownAction(string actionName) | |
| { | |
| Index().ExecuteResult(this.ControllerContext); | |
| } | |
| } | |
| } |
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 Telerik.Sitefinity.Frontend.Mvc.Helpers | |
| <div class="form-group"> | |
| @* NOTE HOW HERE WE PUT THE NAME OF OUR STRING PROPERTY IN THE CONTROLLER - RichText *@ | |
| <sf-html-field class="kendo-content-block" sf-model="properties.RichText.PropertyValue"></sf-html-field> | |
| </div> | |
| <div class="form-group"> | |
| <label>Choose an image: </label> | |
| <sf-image-field class="sf-Media--info modal-settings" | |
| sf-model="properties.ImageId.PropertyValue" | |
| sf-media-settings="@SettingsHelpers.GetMediaSettings("Image")"> | |
| </sf-image-field> | |
| </div> | |
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
| { | |
| "priority": 1, | |
| "components": [ "sf-html-field", "sf-image-field" ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment