In my DXA view, i'm rendering a region using this code
@if (Model.Regions.ContainsKey("RegionName"))
{
@ViewBag.Renderer.RenderRegion(Model.Regions["RegionName"], Html)
}
This works fine. If my page's component presentations contain a template for this specific region, they get rendered here, along with the region XPM tag.
However, let's say I want to render an empty region in my view, to let content editors drag and drop new content in this region using XPM.
In that case, my page object won't contain a region with key "RegionName", so my region will not be rendered. However, the RenderRegion function expects a region model object to be passed along. What's the best way to do this? Should we then just call the RenderRegion method with a new region object, or is there another recommended way to do this ?
@if (Model.Regions.ContainsKey("RegionName"))
{
@ViewBag.Renderer.RenderRegion(Model.Regions["RegionName"], Html)
}
else
{
@ViewBag.Renderer.RenderRegion(new Region(){Name="RegionName"}, Html)
}