Block containing html


I have html code containing some div tags. I want to create a block that contain that predefined html. so when i add the block to page it renders the html in the pages content area. what is simplist way to do that?

Aug 21, 2013 14:10
Aug 21, 2013 14:22
  • Block control using mvc, without creating usercontrol .ascx

Aug 21, 2013 14:23

Create block type (class) and then create a view with the same name as your block. Example: MyBlock.cs and MyBlock.cshtml (under Views and Shared).

public class MyBlock : BlockData


Aug 21, 2013 14:44

Thanks for reply frederik.

here is the block i added

using System;
using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;

namespace Totalkredit.Models.Blocks
[ContentType(DisplayName = "FindBlock", GUID = "c3894d21-69fb-4cf3-b33f-75539ea5f8d4", Description = "")]
public class FindBlock : BlockData
Name = "Find Block body",
Description = "",
GroupName = SystemTabNames.Content,
Order = 20)]
public virtual XhtmlString BlockBody { get; set; }

and  FindBlock.cshtml look like following

@using EPiServer.Core
@using EPiServer.Web.Mvc.Html

@model Totalkredit.Models.Blocks.FindBlock

<div>some text and html</div><div>other divs</div>
@Html.PropertyFor(m => m.BlockBody)

when i add the block to page, i can't see the two div tags or the text?


Aug 21, 2013 15:09

so the MyBlockcontroller is not needed in this scenario? 

Aug 22, 2013 11:48

Where is your view located?

Aug 22, 2013 14:37

FindBlock.cshtml is located at   Views/Shared

Aug 22, 2013 14:41
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.