London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Render blocks with PropertyFor

Vote:
 

I have a custom block with two properties - an image url and an alternative text

 [ContentType(
        GUID = "387A029C-F193-403C-89C9-375A2A6BF028",
        AvailableInEditMode = false,
        DisplayName = "Image" 
        )]

    public class ImageBlock : EPiServer.Core.BlockData
    {
        [UIHint(UIHint.Image)]
        [Display(
            Name = "Image Url",
            Description = "",
            GroupName = SystemTabNames.Content,  
            Order = 10)]
       
        public virtual Url ImageUrl { get; set; }

        [Display(
            Name = "Alternative text",
            GroupName = SystemTabNames.Content,
            Order = 20)]
        [CultureSpecific]
        public virtual string AlternativeText { get; set; }
        
    }

    

I have created a partial view in shared directory /shared/ImageBlock/index.cshtml as 

@model ImageBlock
<img src="@Model.ImageUrl" />

    

So I am hoping when I call something like 

@Html.PropertyFor(p=>p.CurrentPage.TestProperty)

    

My partial view should get called, but the partial view never gets called.

- TestProperty is a property of type ImageBlock

 

Can any body please help me

 

#73643
Aug 02, 2013 17:57
Vote:
 

Does it say it can't find a renderer for the property? If I recall correctly, the correct path to the ImageBlock partial should be "Views/Shared/ImageBlock.cshtml", unless you are pushing the block through a controller.

#73644
Aug 02, 2013 18:58
Vote:
 

Hi, Tahir,

I have not placed my ImageBlock (that I am using as local block and rendering with PropertyFor) inside Views/Shared/ImageBlock.cshtml.

Instead, I have placed it inside Views/Shared/DisplayTemplates/ImageBlock.cshtml

#73670
Aug 05, 2013 14:59
Vote:
 

i'm facing a similar dilema to Tahir, I have tried putting into DisplayTemplates although still get the message their is no render for this block. 

For now I am using seperate controllers although dont think this is the tidiest thing to do. 

#73693
Aug 06, 2013 9:58
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.