TemplateTypeCategories equals different types of "render template types" supported.
public enum TemplateTypeCategories
{
None = 0,
WebFormsPage = 1,
UserControl = 2,
ServerControl = 4,
WebFormsPartial = 6,
WebForms = 7,
MvcController = 8,
Page = 9,
MvcView = 16,
MvcPartialController = 32,
MvcPartialView = 64,
MvcPartial = 96,
Mvc = 120,
}
Having TemplateTypeCategories.MvcController set will trick EPiServer to load the Block as if it was a normal page, remember that block instances doesn't work exactly as page instances do so we must perform this little trick. Otherwise the block instances will be registered as MvcPartialController's, and that we can't load directly in MVC.
I create my PreviewBlockController's a bit more simple than the ones in AlloyMVC.
using EPiServer.Core;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Framework.Web;
using EPiServer.Web;
using System.Web.Mvc;
using Site.Externwebb.Content.Blocks;
namespace Site.Externwebb.Controllers.Blocks
{
[TemplateDescriptor(Inherited = true,
Tags = new[] { RenderingTags.Preview },
TemplateTypeCategory = TemplateTypeCategories.MvcController)]
public class PreviewBlockController : Controller, IRenderTemplate<BlockData>
{
public ActionResult Index(BlockData currentBlock)
{
var baseType = currentBlock.GetType().BaseType;
if (baseType == typeof(BarkerBlock))
{
return View("Barkers", currentBlock);
}
if (baseType == typeof(SlideshowInlineBlock))
{
return View("Inline", currentBlock);
}
// Standard return (general block controller)
return View("RightColumn", currentBlock);
}
}
}
The views are placed by default in ~/Views/PreviewBlock/xxx.cshtml Here is an example
@using EPiServer.Web.Mvc.Html
@model EPiServer.Core.BlockData
@{
Layout = "~/Views/Shared/Masters/_BlockPreviewMaster.cshtml";
}
@section MainContent{
<div id="rightContent" style="width:300px;">
<div id="rightcolumn">
@{ Html.RenderContentData(Model, false); }
</div>
</div>
}
Good enough and easy to administer.
Good luck.
/ Eric Herlitz