我在这里运行教程来构建一个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.cs
Index()
函数的代码是:
// 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
答案 0 :(得分:2)
在我的Web.config
文件中,我必须将<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc...
的{{1}}标记从version
设置为5.2.0.0
以匹配我的NuGet包版本。