在我的asp.net MVC 3应用程序中,我嵌套布局。我按照以下链接:asp.net MVC 3剃刀布局错误
http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx
我主要布局页is_MasterLayout.cshtml再嵌套布局页_fullLayout.cshtml。在_fullLayout.cshtml,我有:
@this.RedefineSection("BodyTitle")
@this.RedefineSection("Showcase")
但我越来越这些线。错误是:
编译错误
说明:该请求提供服务所需资源的编译过程中出现错误。请查看以下具体的错误细节并适当修改您的源代码。
编译器错误消息:CS1928:“ASP._Page_Views_Shared__fullLayout_cshtml”不包含关于“RedefineSection”和最好的扩展方法过载“SectionExtensions.RedefineSection(System.Web.WebPages.WebPageBase,字符串)”的定义有一些无效参数
源错误:
第9行:
第10行:} 第11行:@ this.RedefineSection( “BodyTitle”) 第12行:@ this.RedefineSection( “橱窗”)13 线: @RenderBody()
帮助我的方法是这样定义的:
public static class SectionExtensions
{
private static readonly object _o = new object();
public static HelperResult RenderSection(this WebPageBase page, string sectionName, Func<object, HelperResult> defaultContent)
{
if (page.IsSectionDefined(sectionName))
return page.RenderSection(sectionName);
else
return defaultContent(_o);
}
public static HelperResult RedefineSection(this WebPageBase page, string sectionName)
{
return RedefineSection(page, sectionName, defaultContent: null);
}
public static HelperResult RedefineSection(this WebPageBase page, string sectionName, Func<object, HelperResult> defaultContent)
{
if (page.IsSectionDefined(sectionName))
page.DefineSection(sectionName,() => page.Write(page.RenderSection(sectionName)));
else if (defaultContent != null)
page.DefineSection(sectionName,() => page.Write(defaultContent(_o)));
return new HelperResult(_ => { });
}
}
请提出解决方案。
问候, 阿西夫·哈米德
我像这样使用它:@this。RedefineSection(“BodyTitle”,@
默认SubLayout标题
) @ this.RedefineSection(“橱窗”,@默认SubLayout展示
),但还是同样的错误 – DotnetSparrow 2011-12-17 12:39:13一个这样说,我并没有定义内容页本节。 – DotnetSparrow 2011-12-17 12:43:05
@RenderSection(“TitleSection”,required:false) @RenderBody()在主布局 – Neha 2011-12-17 12:49:57