November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi!
If you are not rendering your content using PropertyFor you need to add some html yourself that informs the UI that this area should be on page editable for a specific property. There is an extension method called EditAttributes that can help with that. In you case it could look something like this:
<div @Html.EditAttributes(m => m.SiteLogotypeUrl)>
@{ Html.RenderAction("Logo", "SiteLogotypeBlock2"); }
</div>
Regards
Per Gunsarfs
I do not specify a Model on Layout page, so I get the following error, when I inlcude EditAttributes:
An expression tree may not contain a dynamic operation
This error is solved by specifying @model (http://stackoverflow.com/questions/4155392/razor-view-engine-an-expression-tree-may-not-contain-a-dynamic-operation), but I can't specify @model PROJECT.Web.Models.Pages.StartPage, as it wouldn't work on pages other than StartPage.
Ok, then you can should be able the overload of EditAttributes that is not strongly typed instead.
@Html.EditAttributes("NameOfMyProperty")
Unfortunately, this doesn't help either, I do not get the DOPE support. I have added your suggestion.
<div class="span2" @Html.EditAttributes("SiteLogotypeUrl")>
@{ Html.RenderAction("Logo", "SiteLogotypeBlock2"); }
</div>
Hmm, and is the property on your content type called "SiteLogotypeUrl"? Looking at your first code sample it looks like the property on your StartPage is called "SiteLogotype".
What html is rendered for the div when the page is openend in the edit view?
Yes, that's the trick!! Thx a lot for your time, so sorry about such a mistake!
I used this tutorial to switch between SiteLogotypeBlock2 rendering in WebForms and MVC:
http://world.episerver.com/Blogs/Jonas-Bergqvist/Dates/2012/11/Rendering-EPiServer-MVC-request--Part-1/
When I use @Html.PropertyFor(m => m.SiteLogotype) on start page, for example, I get the correct rendering and DOPE support.
However, I do not want to add logo to each page, I want to add it to "master" _layout page. Here, I cannot use @Html.PropertyFor(m => m.SiteLogotype), so I am using @{ Html.RenderAction("Logo", "SiteLogotypeBlock2"); } instead.
This is how my controller looks like (I have the edit hint):
[HttpGet]
public ActionResult Logo()
{
if (StartPage != null)
{
var viewModel = new SiteLogotypeBlock2ViewModel();
AutoMapper.Mapper.Map(StartPage.SiteLogotype, viewModel);
var editingHints = ViewData.GetEditHints<SiteLogotypeBlock2ViewModel, SiteLogotypeBlock2>();
editingHints.AddConnection(x => x.LogotypeUrl, x => x.SiteLogotypeUrl);
return PartialView("SiteLogotypeBlock2", viewModel);
}
return null;
}
Earlier, I had a method with currentBlock as a parameter, but it is always null, so instead I need to read it from start page.
[HttpGet]
public override ActionResult Index(SiteLogotypeBlock2 currentBlock)
{
// currentBlock always null!
}
Is this fixable or should we have an implementation that is based on the fact that Blocks on Layout pages are not supported?