我得到了下面的错误,但我已经在下面的布局页面上定义了它。我将@(IsSectionDefined
更改为@if(IsSectionDefined
,因为我需要在else
语句中写入null
。为什么这会成为一个问题?
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}
我能够用他的助手函数修复它,该函数位于:有没有办法用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);
}