Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
.net 如何定义MVC3Razor视图引擎在整个站点中的使用?_.net_Web Config_Asp.net Mvc 3_Razor - Fatal编程技术网

.net 如何定义MVC3Razor视图引擎在整个站点中的使用?

.net 如何定义MVC3Razor视图引擎在整个站点中的使用?,.net,web-config,asp.net-mvc-3,razor,.net,Web Config,Asp.net Mvc 3,Razor,我为UrlHelper编写了一个简单的扩展方法: public static class ExtensionMethods { private const string ImagesFolder = "~/Images"; public static string Images(this UrlHelper url) { return url.Content(ImagesFolder); } } 上述代码位于/Helper/ExtensionM

我为UrlHelper编写了一个简单的扩展方法:

public static class ExtensionMethods
{
    private const string ImagesFolder = "~/Images";

    public static string Images(this UrlHelper url)
    {
        return url.Content(ImagesFolder);
    }
}
上述代码位于
/Helper/ExtensionMethods.cs
中。它工作得很好,但我需要使用MyNamespace.Helper添加
在我想要使用
Url.Images()
的每个cshtml中。以前我们会在
web.config
中添加另一行:

<system.web>
    <pages>
        <namespaces>
            <add namespace="MyNamespace.Helper"/>
        </namespaces>
    </pages>
</system.web>

但上面这些似乎并没有被剃须刀刮到。我尝试将using语句添加到
\u ViewStart.cshtml
,结果相同


那么,Razor如何在整个站点中指定一个using呢?

正如公认的链接答案所建议的那样,您可以通过添加到配置文件的一节,将“using”添加到所有视图中

对于特定视图,您可以使用

@使用MyNamespace.Helper


绝对是个傻瓜——只是在我的搜索中没有发现。感谢您的关注:-)