Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Not sure about Html.RenderPartial(). Haven't tried it with local blocks.
Try following:
@Html.PropertyFor(m => m.SiteSettings.MySiteSettingsPage.SiteStartPage.ToPage<StartPage>().FooterSettings)
Then it depends on what you need to accomplish.
1) If you don't need a controller for your block type -> then just name your view tha same name as block - FooterSettings.cshtml. This will tell EPiServer to skip any controllers and render view directly.
2) If you need custom logic (like construct custom view model) you may need a controller for this block.
public class FooterSettingsBlockController : BlockController<FooterSettingsBlock>
{
public ActionResult(FooterSettingsBlock currentBlock)
{
return PartialView(".....", model);
}
}
Keep in mind that using second choice you need to rename view in order to EPiServer understand that you need a controller for your block. A good practice is to start those partial views with underscrore - "_" -> "/Views/Shared/_FooterSettings.cshtml".
I have a page with local block
[ContentType(GUID = "d9298163-9046-4bd1-9ff1-81e5abb83a80", AvailableInEditMode = true)]
public class StartPage : BasePageData
{
private const string LeftNavigationMenu = "Left Navigation";
[CultureSpecific(true)]
[Display(GroupName = SystemTabNames.Content, Order = 50)]
public virtual ContentArea MainContentAreaTop { get; set; }
[CultureSpecific(true)]
[Display(GroupName = SystemTabNames.Content, Order = 60)]
public virtual ContentArea MainContentArea { get; set; }
[Display(GroupName = FooterSettingsBlock.FooterTab, Order = 100)]
public virtual FooterSettingsBlock FooterSettings { get; set; }
And I try to render partial view and send to view FooterSettings:
@{
Html.RenderPartial("Shared/Footer", @Model.SiteSettings.MySiteSettingsPage.SiteStartPage.ToPage<StartPage>().FooterSettings);
}
I have a logic in StartPageController:
public class StartPageController : BasePageController<StartPage>
{[HttpPost]
public ActionResult Subscribe(SubscriptionViewModel model)
{
return Redirect("/");
}
}
and try to call this method from partial Footer view:
@model Valtech.Core.Website.Models.Blocks.FooterSettingsBlock
<div>
<h3>@Html.PropertyFor(m => m.SubscriptionHeading)</h3>
@Html.Partial("shared/Subscription", new SubscriptionViewModel {CurrentBlock=Model})
</div>
Subscription partial view:
@model Valtech.Core.Website.Models.ViewModels.SubscriptionViewModel
@using (Html.BeginForm("Subscribe", "StartPage", FormMethod.Post, new { id = "subscribeForm" }))
{
<input name="Email" id="userEmail" type="text" placeholder="@Model.CurrentBlock.EnterEmailText"/>
<a href="javascript:document.getElementById('subscribeForm').submit()">@Model.CurrentBlock.SubmitText</a>
}
When I click my link, I get TypeMismatchException and this stackTraice: