我在我的 asp.net mvc2 中使用了以下类型的代码。
public class MyViewPage : ViewPage
{
protected override void OnPreInit(EventArgs e)
{
CustomerSettingData csd = GetCustomerData(_customerId);
this.Theme = viewMetaData.Theme;
}
}
我将在其中根据登录的客户找到主题,然后呈现主题。我怎样才能在 Razor Views 中完成这种事情。如果我尝试在 Razor 视图中使用它,它会给出错误消息。
System.Web.HttpCompileException (0x80004005): c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\59ad3d7b\f111dcde\App_Web_index.cshtml.e33b3359.tnkwzx_a.0.cs(79) : 错误 CS0115: 'ASP._Page_Areas_ERP_Views_Products_Index_cshtml.Execute()': 在 System.Web.Compilation.BuildProvidersCompiler.PerformBuild() 在 System.Web.Compilation 的 System.Web.Compilation.AssemblyBuilder.Compile() 上找不到合适的方法来覆盖.BuildManager.CompileWebFile(VirtualPath virtualPath) 在 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) 在 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context , VirtualPath virtualPath, Boolean noBuild,System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) 在 System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc。 IBuildManager.FileExists(String virtualPath) at System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath) at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, ListMvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath) at System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath) at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, ListMvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath) at System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath) at System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List
1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations) at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations) at System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache) at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClassc.<FindView>b__b(IViewEngine e) at System.Web.Mvc.ViewEngineCollection.Find(Func
2 在 System.Web.Mvc.ViewResult.FindView(ControllerContext context) 在 System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName) 在 System.Web.Mvc.ViewResultBase.FindView(ControllerContext context) 的查找,布尔 trackSearchedPaths) (ControllerContext 上下文) 在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 在 System.Web.Mvc.ControllerActionInvoker.<>c_ DisplayClass1c.b _19() 在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter( System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 处的IResultFilter 过滤器、ResultExecutingContext preContext、Func1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 过滤器、ActionResult actionResult)
我无法理解此错误消息并修复解决方案。如果我使用
<pages pageBaseType="System.Web.Mvc.WebViewPage">
,我没有收到异常,此异常仅发生在自定义视图页面中。
高度赞赏任何合适的链接或指导。
当我尝试以下操作时,我收到通知this.Theme
不可用。
public class MyViewPageForRazorView : System.Web.WebPages.WebPageBase