c# - Mono Mac 上的 ASP.net MVC Razor View

标签 c# asp.net-mvc macos visual-studio asp.net-mvc-4

我使用 Visual Studio Community Edition for Mac 创建了一个 ASP.net MVC 应用程序。当我运行默认的 HomeController 和索引 View 时工作正常。然后我制作了一个 BookController 并在内部 View 中添加了一个文件夹 Book 和 Index.cshtml 文件。但是我不断收到以下错误:

System.InvalidOperationException The view found at '~/Views/book/Index.cshtml' was not created.

描述:

HTTP 500.Error processing request.

详细信息:

Non-web exception. Exception origin (name of application or object): System.Web.Mvc. Exception stack trace: at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00061] in :0 at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00080] in :0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in :0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (System.Collections.Generic.IList1[T] filters, System.Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0000b] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (System.Collections.Generic.IList1[T] filters, System.Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0009b] in :0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters (System.Web.Mvc.ControllerContext controllerContext, System.Collections.Generic.IList1[T] filters, System.Web.Mvc.ActionResult actionResult) [0x0000a] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21+<>c__DisplayClass2b.<BeginInvokeAction>b__1c () [0x0008a] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21.<BeginInvokeAction>b__1e (System.IAsyncResult asyncResult) [0x00041] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult1[TResult].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in :0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d (System.IAsyncResult asyncResult, System.Web.Mvc.Controller+ExecuteCoreState innerState) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at (wrapper delegate-invoke) System.Web.Mvc.Async.EndInvokeVoidDelegate1[System.Web.Mvc.Controller+ExecuteCoreState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.Controller/ExecuteCoreState) at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase1[TResult].End () [0x00029] in :0 at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in :0 at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] in :0 at System.Web.Mvc.Controller.EndExecuteCore (System.IAsyncResult asyncResult) [0x00000] in :0 at System.Web.Mvc.Controller.b__15 (System.IAsyncResult asyncResult, System.Web.Mvc.Controller controller) [0x00000] in :0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase1[TResult].End () [0x00029] in :0 at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in :0 at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] in :0 at System.Web.Mvc.Controller.EndExecute (System.IAsyncResult asyncResult) [0x00000] in :0 at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute (System.IAsyncResult asyncResult) [0x00000] in :0 at System.Web.Mvc.MvcHandler.b__5 (System.IAsyncResult asyncResult, System.Web.Mvc.MvcHandler+ProcessRequestState innerState) [0x00000] in :0 at (wrapper delegate-invoke) System.Web.Mvc.Async.EndInvokeVoidDelegate1[System.Web.Mvc.MvcHandler+ProcessRequestState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.MvcHandler/ProcessRequestState)<br/> at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in :0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in :0 at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in :0 at System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] in :0 at System.Web.Mvc.MvcHandler.EndProcessRequest (System.IAsyncResult asyncResult) [0x00000] in :0 at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest (System.IAsyncResult result) [0x00000] in :0 at System.Web.HttpApplication.async_handler_complete_cb (System.IAsyncResult ar) [0x00015] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class

我用 Google 搜索了一下,有人说我必须确保 views 文件夹中的 web.config 如下所示:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

那就是它与 system.web.mvc 的版本相匹配,在 system.web.mvc 中查看版本是:

5.2.3

并且 HomeController 中的默认 View 有效。我第一次在 Mac 上尝试 ASP.net MVC,在 Windows 上从未遇到过此类问题。

欢迎任何帮助。

更新 Controller 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestMvcFromMac.Models;

namespace TestMvcFromMac.Controllers
{
 public class BookController : Controller
 {

    //Category category = new Category();


    public ActionResult Index()
    {
        return View ();
    }


 }
}

最佳答案

中等 适用于 Mac 的 Visual Studio 2017 MVC 版本 5.3.2

我遇到了完全相同的问题。我的索引 View 有效,而其他操作无效,给出了同样的错误。我不知道为什么,但是当我在 Controller 中的操作开始时手动添加路由属性时,这是我的案例的解决方案

步骤 1) 将以下行添加到 routeconfig.cs 文件

 routes.MapMvcAttributeRoutes();

2) 手动添加路由属性到 Action 喜欢

  [Route("ViewName/ActionName/")]
    public ActionResult ActionName()
    {....
  return View(the_model);
   }

关于c# - Mono Mac 上的 ASP.net MVC Razor View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43959733/

相关文章:

objective-c - 难道我不允许覆盖 -sendEvent : in my NSApplication subclass?

c# - 为什么不能克隆 IEnumerator?

c# - 使用反射从基类构造函数在派生类上设置值

c# - 迭代列表<dynamic>

c# - 如何延长http响应的时间长度

python - 使用 Homebrew 安装 Python 后找不到 IDLE

c# - 当所有子窗口都关闭时,如何将控件集中在 MDIParent 中?

c# - 具有动态内容的动态页面

c# - 为什么需要在 UnitOfWork EF 上实现 Dispose 模式?

c - OSX 命令行 Readline 等效项