View Rendering based on a Data Source
Model
using System.Web;
namespace Solution.Models
{
public class Image
{
public Image() { }
public HtmlString Image { get; set; }
}
}
Controller
using Sitecore.Mvc.Presentation;
using Sitecore.Web.UI.WebControls;
using System.Web;
using System.Web.Mvc;
using Solution.Models;
namespace Solution.Controllers
{
public class ImageController: Controller
{
public ActionResult Index()
{
return View(CreateModel());
}
public Image CreateModel()
{
var item = RenderingContext.Current.Rendering.Item;
var image = new Image()
{
Image = new HtmlString(FieldRenderer.Render(item, "Image", "mw=400"))
};
return image;
}
}
}
View
@model Solution.Models.Image
@Model.Image