In my asp.net MVC 3 application, I have nested layouts. I have followed following link:
http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx
My main layout page is_MasterLayout.cshtml and then a nested layout page _fullLayout.cshtml. In _fullLayout.cshtml, I have:
@this.RedefineSection("BodyTitle")
@this.RedefineSection("Showcase")
but I am getting on these lines. Error is:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1928: ‘ASP._Page_Views_Shared__fullLayout_cshtml’ does not contain a definition for ‘RedefineSection’ and the best extension method overload ‘SectionExtensions.RedefineSection(System.Web.WebPages.WebPageBase, string)’ has some invalid arguments
Source Error:
Line 9:
Line 10: }
Line 11: @this.RedefineSection(“BodyTitle”)
Line 12: @this.RedefineSection(“Showcase”)
Line 13: @RenderBody()
my helper methods are defined like this:
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(_ => { });
}
}
Please suggest solution.
Regards,
Asif Hameed
RedefineSection helper contains two or more argument
but you are passing only one in your view
According to
http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx
you have to put something