How do I import a namespace in Razor View Page?

后端 未结 11 1386
迷失自我
迷失自我 2020-11-22 11:03

How to import a namespace in Razor View Page?

11条回答
  •  孤街浪徒
    2020-11-22 11:35

    I found this http://weblogs.asp.net/mikaelsoderstrom/archive/2010/07/30/add-namespaces-with-razor.aspx which explains how to add a custom namespace to all your razor pages.

    Basically you can make this

    using Microsoft.WebPages.Compilation;
    public class PreApplicationStart
    {
       public static void InitializeApplication()
       {
           CodeGeneratorSettings.AddGlobalImport("Custom.Namespace");
       }
    }
    

    and put the following code in your AssemblyInfo.cs

    [assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "InitializeApplication")]
    

    the method InitializeApplication will be executed before Application_Start in global.asax

提交回复
热议问题