我在App_Code上创建了RazorFunctions.cshtml文件
@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" : "";
}
}
当我编译时,它给我两个错误(编译成功并且现场工作没有问题),但是这些错误很烦人。
RazorFunctions.cshtml与Content一样(已尝试编译,但不适用于cshtml文件)
Global.asax.cs是:
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>());
}
}
和
<%@ Application Codebehind="Global.asax.cs" Inherits="Bouron.Web.MvcApplication" Language="C#" %>
这是我第一次使用App_Code,所以我不知道该怎么做,所有搜索都返回ASP.NET 1-2结果,这些结果已经过时,甚至没有 Razor ,所以我不确定该怎么做。我解决了。
我正在使用Visual Studio 2015(以防万一)
最佳答案
经过进一步调查,我发现这是一个已知问题。
来源:https://support.microsoft.com/en-us/kb/3025133
ASP.NET和Web开发
错误CS0234类型或 namespace 名称“Linq”在 namespace “系统”中不存在(您是否缺少程序集引用?)
假定您在Visual Studio 2015 RC中为C#和VB使用新的语言功能。在Web窗体页面或Razor View 中使用C#或VB时,会收到运行时错误。
要变通解决此问题,请安装Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet程序包。此程序包将用基于Roslyn的提供程序代替ASP.NET的内置CodeDom提供程序。