I created a RazorFunctions.cshtml file on App_Code

@functions {
    public static string GetActiveClassIf(string controllerName, string actionName = null)
    {
        var routeData = @HttpContext.Current.Request.RequestContext.RouteData;
        string currentController = routeData.Values["controller"].ToString();
        string currentAction = routeData.Values["action"].ToString();
        return controllerName == currentController &&
            (String.IsNullOrEmpty(actionName) || currentAction == actionName) ? "active" : "";
    }
}

and when I compile, it give me 2 errors (compilation get success and site work without problem) but the errors are annoying.

The RazorFunctions.cshtml are as Content (tried compile but doesn't work with cshtml files of course)

Global.asax.cs is :

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        ModelMetadataConfig.RegisterModelMetadata();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>());
        //Database.SetInitializer(new DropCreateDatabaseAlways<ApplicationDbContext>());
    }
}

and

<%@ Application Codebehind="Global.asax.cs" Inherits="Bouron.Web.MvcApplication" Language="C#" %>

This is the first time I use the App_Code so I don't know what else to do, all search returns ASP.NET 1-2 results, are out of date where razor doesn't even exist so I'm not sure how can I solve this.

I'm using Visual Studio 2015 (just in case it matters)

推荐答案

After further investigation I found that this is a known issue.

source: https://support.microsoft.com/en-us/kb/3025133

ASP.NET and Web Development

  • When you create a Web Forms 4.5 WAP and open a Web Form page, you receive the following errors in the Errors List window:

  • The project will run without any issues. Error CS0234 The type or namespace name 'global_asax' does not exist in the namespace 'ASP' (are you missing an assembly reference?) Error CS0234 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) Assume that you use new language features for C# and VB in Visual Studio 2015 RC. You receive a runtime error when you use C# or VB in a Web Form page or in Razor Views.

To work around this issue, install Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package. This package will substitute the Roslyn-based provider for the in-box CodeDom providers for ASP.NET.

Asp.net相关问答推荐

asp.net dropdownlist - 在 db 值之前添加空行

Web api 不支持 POST 方法

为什么默认情况下不允许 GET 请求返回 JSON?

在 cookie 中存储多个值

从 RowDataBound 事件的 gridview 从单元格中获取值

在 ASP.NET 中将虚拟路径转换为实际 Web 路径

ASP.net 与 PHP( Select 什么)

ASP.NET 会话超时测试

Page.IsValid 是如何工作的?

使 Web.config 转换在本地工作

Web.Config 中的 Assemblies node 的用途是什么?

Html.RenderAction 和 Html.Action 的区别

在 ASP.NET 中使用 MasterPages 时使用 JQuery 的正确方法?

调查 Web.Config 重复部分原因的步骤

IronRuby死了吗?

为什么 IFormFile 显示为空,我该如何解决?

您可以从 web.config 文件中的其他位置提取 log4net AdoNetAppender 的 connectionString 吗?

中继器中的中继器

使用 FileUpload Control 获取文件的完整路径

禁用文本框的模型绑定