2011-12-17 4 views
0

내 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.

@this.RedefineSection("BodyTitle") 
@this.RedefineSection("Showcase") 

을하지만, 나는이 선에 무엇입니까 : _fullLayout.cshtml, 나는있다. 오류는 다음과 같습니다

컴파일 오류

설명 : 오류가이 요청을 제공하는 데 필요한 리소스 컴파일하는 동안 오류가 발생했습니다. 다음 특정 오류 정보를 검토하고 소스 코드를 적절히 수정하십시오.

컴파일러 오류 메시지 : 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(_ => { }); 
    } 

} 

솔루션을 제안 해주십시오.

감사합니다, 아시프 하미드

답변

0

RedefineSection 도우미는 두 개 이상의 인수

RedefineSection(this WebPageBase page, string sectionName) 

이 포함되어 있지만

@this.RedefineSection("BodyTitle") 
@this.RedefineSection("Showcase") 

따르면 당신이 뭔가를 넣어야 할

http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx

에보기에서 하나를 전달하는

@this.RedefineSection("TitleSection", 
        @<h1>Default SubLayout title</h1>) 
+0

나는 이것을 다음과 같이 사용했다 : @this.RedefineSection은 (을 전시 SubLayout

기본 @ "쇼케이스") this.RedefineSection @ 하지만이 언급 – DotnetSparrow

+0

하나 여전히 같은 오류 (

기본 SubLayout 제목

@ "BodyTitle은"), I 콘텐츠 페이지에서이 섹션을 정의하지 않았다 . – DotnetSparrow

+0

@RenderSection ("TitleSection", 필수 : ​​거짓) 마스터 레이아웃의 @RenderBody() – Neha

0

다음 단계는 클래스 "SectionExtensions"의 네임 스페이스를 가져 문제를 1. 문제의 해결을 위하여 노력한다. 2. RedefineSection을 사용하는 레이아웃 페이지에서 페이지 상단에 해당 이름 공간을 가져옵니다.

@ yournamespace를 사용합니다.

감사합니다.

+0

이 클래스는 어떤 네임 스페이스에도 속하지 않습니다. 나는 그것을 네임 스페이스로 묶었고 맨 위에 "@using CreditRegistry.Models"을 추가했지만 여전히 같은 오류가 발생했습니다. – DotnetSparrow

+0

둘 다 materpage에 네임 스페이스를 넣습니다. 중첩 된 마스터 레이아웃. – dotnetstep