Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 asp.net MVC 3剃须刀布局错误_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 3 asp.net MVC 3剃须刀布局错误

Asp.net mvc 3 asp.net MVC 3剃须刀布局错误,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,在我的asp.net MVC 3应用程序中,我有嵌套的布局。我关注以下链接: 我的主布局页面是_MasterLayout.cshtml,然后是嵌套布局页面_fullLayout.cshtml。在_fullLayout.cshtml中,我有: @this.RedefineSection("BodyTitle") @this.RedefineSection("Showcase") 但我正在接这些电话。错误是: 编译错误 描述:编译服务此请求所需的资源时出错。请查看以下特定错误详细信息,并适当修改源

在我的asp.net MVC 3应用程序中,我有嵌套的布局。我关注以下链接:

我的主布局页面是_MasterLayout.cshtml,然后是嵌套布局页面_fullLayout.cshtml。在_fullLayout.cshtml中,我有:

@this.RedefineSection("BodyTitle")
@this.RedefineSection("Showcase")
但我正在接这些电话。错误是:

编译错误

描述:编译服务此请求所需的资源时出错。请查看以下特定错误详细信息,并适当修改源代码

编译器错误消息:CS1928:“ASP.\u页面\u视图\u共享\u完整布局\u cshtml”不包含“RedefineSection”的定义,并且最佳扩展方法重载“SectionExtensions.RedefineSectionSystem.Web.WebPages.WebPageBase,string”具有一些无效参数

源错误:

第9行: 第10行:} 第11行:@this.residenceBodyTitle 第12行:@this.com 第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(_ => { });
    }

}
请提出解决方案

问候,,
Asif Hameed

以下步骤解决您的问题 1.获取类SectionExtensions的命名空间。 2.在使用“重定义”部分的布局页面中,使用导入页面顶部的名称空间

@使用名称空间


谢谢。

重新定义节帮助程序包含两个或多个参数

RedefineSection(this WebPageBase page, string sectionName)
但在你看来,你只通过了一个

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

你得放点东西

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

我是这样使用的:@this.RedefineSectionBodyTitle、@Default SubLayout title@this.RedefineSectionShowcase、@Default SubLayout showcase,但仍然是同一个错误提到这一点,我没有在内容页中定义此部分。@RenderSectionTitleSection,必需:false@RenderBody在主布局中该类不在任何命名空间下。我用名称空间将其括起来,并在顶部添加了@using CreditRegistry.Models,但仍然存在相同的错误。将名称空间放在两个页面中。主布局以及嵌套布局。