Try our conversational search powered by Generative AI!

Problem using DOPE for Block on Layout page in MVC

Vote:
 

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?

#64226
Dec 13, 2012 15:42
Vote:
 

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

#64229
Dec 13, 2012 16:13
Vote:
 

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.

#64232
Dec 13, 2012 16:25
Vote:
 

Ok, then you can should be able the overload of EditAttributes that is not strongly typed instead.

@Html.EditAttributes("NameOfMyProperty")

#64233
Dec 13, 2012 16:34
Vote:
 

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>

 

#64318
Dec 17, 2012 18:00
Vote:
 

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?

#64336
Dec 18, 2012 10:05
Vote:
 

Yes, that's the trick!! Thx a lot  for your time, so sorry about such a mistake!

#64357
Dec 18, 2012 13:54
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.