Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Create a block type
using System;
using System.ComponentModel.DataAnnotations;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
namespace EPiServerBlogTutorial.Models.Blocks
{
[ContentType(
DisplayName = "Advertisement Block",
GUID = "8a05cc73-6a38-46a5-b173-bb9974a0692e",
Description = "Use this block to add advertisement")]
public class AdvertisementBlock : BlockData
{
[CultureSpecific]
[Display(
Name = "Radio A Text ",
Description = "Radio A Text field's description",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual string RadioAText { get; set; }
[CultureSpecific]
[Display(
Name = "Radio B Text ",
Description = "Radio B Text field's description",
GroupName = SystemTabNames.Content,
Order = 20)]
public virtual string RadioBText { get; set; }
[CultureSpecific]
[Display(
Name = "Text",
Description = "Short text",
GroupName = SystemTabNames.Content,
Order = 30)]
public virtual XhtmlString Text { get; set; }
}
}
using System.Web.Mvc;
using EPiServer;
using EPiServer.Core;
using EPiServer.Web;
using EPiServer.Web.Mvc;
using EPiServerBlogTutorial.Models.Blocks;
namespace EPiServerBlogTutorial.Controllers
{
public class AdvertisementBlockController : BlockController<AdvertisementBlock>
{
public override ActionResult Index(AdvertisementBlock currentBlock)
{
return PartialView(currentBlock);
}
}
}
@model EPiServerBlogTutorial.Models.Blocks.AdvertisementBlock
<strong>Advertisement:</strong>
<input type="radio" id="html" name="fav_language" value="@Model.RadioAText">
<label for="html">Model.RadioAText</label><br>
<input type="radio" id="html" name="fav_language" value="@Model.RadioBText">
<label for="html">Model.RadioBText</label><br>
@Html.PropertyFor(x => x.Text)
"RadioRichTextBlock" which contains a Radio A Text field, Radio B Text field, and an XhtmlString field for the TinyMCE. Showing/Hiding the text is part of the frontend. An editor can then use and place the block wherever needed.