无法让 Razor MVC 在 Mono 上工作

Can't get Razor MVC to work on Mono

我正在 运行 通过这里的教程构建一个 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 

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