November Happy Hour will be moved to Thursday December 5th.

Block containing html

Vote:
 

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?

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

#74142
Aug 21, 2013 14:23
Vote:
 

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).

[ContentType()]
public class MyBlock : BlockData
{        
}

    

#74146
Aug 21, 2013 14:44
Vote:
 

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
{
[Display(
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>
<div>some text and html</div><div>other divs</div>
@Html.PropertyFor(m => m.BlockBody)
</div>

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

 

#74156
Aug 21, 2013 15:09
Vote:
 

so the MyBlockcontroller is not needed in this scenario? 

#74199
Aug 22, 2013 11:48
Vote:
 

Where is your view located?

#74219
Aug 22, 2013 14:37
Vote:
 

FindBlock.cshtml is located at   Views/Shared

#74220
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.