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

PartialView returned in a controller

Vote:
 

Hi,

We are in process of migrating from EPiServer to Optimizely 12 (.NET6), and have encountered this issue of partial view returned as an ActionResult in a controller.

previous code:

public override ActionResult Index(MyBlock currentBlock)
{
    //some logic

     return PartialView(viewModel);
}

now in .Net6, there is still possibility to override `public override ActionResult Index`  but `return PartialView(...)` is not recognized: "Cannot resolve symbol 'Partial View'".

Previously `EPiServer.Web.Mvc.BlockController` inherited from `ActionControllerBase : Controller`, now it is not, `EPiServer.Web.Mvc.PartialContentController` inherited from `PartialContentComponent` only, which does not have that method.

How shoud I approach that?

#303377
Jun 12, 2023 9:51
Vote:
 

Hi Mateusz,

You now create your Blocks using ViewComponents like so:

[ContentType(
    DisplayName = "General Content Block",
    GUID = "some-guid",
    Description = "A super helpful description.",
    GroupName = SystemTabNames.Content)]
public class GeneralContentBlock : BlockData, IContentBlock
{
// Block properties go here as normal
}

public sealed class GeneralContentBlockViewComponent : BlockComponent<GeneralContentBlock>
{
    protected override IViewComponentResult InvokeComponent(GeneralContentBlock currentContent)
    {
        return View(currentContent);
    }
}

Your Razor files are the same, except the default path is `/Views/Shared/Components/GeneralContentBlock/cshtml`

#303381
Edited, Jun 12, 2023 11:22
* 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.