作者:手机用户2502912857 | 来源:互联网 | 2023-12-09 19:22
本文讨论了在ASP中创建RazorFunctions.cshtml文件时出现的问题,即ASP.global_asax不存在于命名空间ASP中。文章提供了解决该问题的代码示例,并详细解释了代码中涉及的关键概念,如HttpContext、Request和RouteData等。通过阅读本文,读者可以了解如何解决该问题并理解相关的ASP概念。
I created a RazorFunctions.cshtml file on App_Code
我创建了一个RazorFunctions。cshtml文件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)
RazorFunctions。cshtml是作为内容的(尝试编译,但当然不能使用cshtml文件)
Global.asax.cs is :
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());
//Database.SetInitializer(new DropCreateDatabaseAlways());
}
}
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.
这是我第一次使用App_Code,所以我不知道还能做什么,所有的搜索返回ASP。NET 1-2的结果,已经过时了,而razor根本不存在,所以我不知道该怎么解决这个问题。
I'm using Visual Studio 2015 (just in case it matters)
我使用的是Visual Studio 2015(以防万一)
8 个解决方案