0

I am getting the error below but I have it defined on the Layout page below. I changed the @(IsSectionDefined to @if(IsSectionDefined because I need to write null in the else statement. Why would this be an issue?

The following sections have been defined but have not been rendered for the layout page "~/Areas/Directors/Views/Shared/_MembersFormLayout.cshtml": "FormCallback".

Layout.cshtml

 <form data-bind="form:{ id: @Model.FormId, callback: @if (IsSectionDefined("FormCallback")){RenderSection("FormCallback", false);}else {@(Html.Raw("null"))}}">

Page.cshtml

@section FormCallback{members.event.updateImage}
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341

1 Answers1

0

I was able to fix it with his helper function found at Is there a way to make a @section optional with the asp.net mvc Razor ViewEngine? .

<form class="clearfix" action="@Request.RawUrl" data-bind="form:{ id: @Model.FormId, callback: @this.RenderSection("FormCallback", @<text>null</text>)}">

public HelperResult RenderSection(string name, Func<dynamic, HelperResult> defaultContents)
{
    if (IsSectionDefined(name))
    {
        return RenderSection(name);
    }
    return defaultContents(null);
}
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341