【问题标题】:Can't get Razor MVC to work on Mono无法让 Razor MVC 在 Mono 上工作
【发布时间】:2016-06-04 19:07:10
【问题描述】:

我正在通过这里的教程来构建一个 ASP.NET MVC 网站:http://www.asp.net/mvc/overview/getting-started/introduction/adding-a-view。我使用的不是 MSVC,而是 MonoDevelop,因为我使用的是 Linux 系统。

当我尝试将 Razor 视图添加到我的 HelloWorld 控制器的 Index 函数时遇到了一些问题。现在,Views/HelloWorld/Index.cshtml 的代码是这样的:

<h2>Index</h2>

<p>Hello from our View Template!</p>

Controllers/HelloWorldController.csIndex() 函数的代码是这样的:

// GET: /HelloWorld/
public ActionResult Index()
{
    return View();
}

但是当我转到http://127.0.0.1:8080/HelloWorld/ 时,我收到了 500 错误。它正在返回此信息:

System.InvalidOperationException
Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Web.WebPages.Razor.

异常堆栈跟踪:

at System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory (System.String typeName) [0x00030] in <filename unknown>:0 
  at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (System.Collections.Concurrent.TKey key, System.Func`2 valueFactory) [0x00037] in <filename unknown>:0 
  at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore (System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup config, System.String virtualPath, System.String physicalPath) [0x0004f] in <filename unknown>:0 
  at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig (System.String virtualPath, System.String physicalPath) [0x00038] in <filename unknown>:0 
  at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig () [0x00006] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.CreateHost () [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.get_Host () [0x00008] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode () [0x00008] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType () [0x00000] in <filename unknown>:0 
  at System.Web.Compilation.BuildManagerDirectoryBuilder.GetBuildProviderCodeDomType (System.Web.Compilation.BuildProvider bp) [0x00000] in <filename unknown>:0 
  at System.Web.Compilation.BuildManagerDirectoryBuilder.AssignToGroup (System.Web.Compilation.BuildProvider buildProvider, System.Collections.Generic.List`1 groups) [0x0007a] in <filename unknown>:0 
  at System.Web.Compilation.BuildManagerDirectoryBuilder.Build (Boolean single) [0x00151] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) [0x00019] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) [0x00063] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) [0x00040] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) [0x00006] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetCompiledType (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x0001c] in <filename unknown>:0 
  at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00080] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0000b] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0004f] in <filename unknown>:0 

【问题讨论】:

标签: c# asp.net-mvc razor mono monodevelop


【解决方案1】:

在我的Web.config 文件中,我必须将&lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc...version 标记从5.2.0.0 设置为5.2.3.0 以匹配我的NuGet 包版本。

【讨论】:

    猜你喜欢
    • 2012-07-07
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 2020-07-31
    • 2013-01-04
    相关资源
    最近更新 更多