sha*_*ani 9 c# macos asp.net-mvc visual-studio asp.net-mvc-4
我使用Visual Studio Community Edition for Mac创建了一个ASP.net MVC应用程序.当我运行默认的HomeController和索引视图工作正常.然后我做了一个BookController并在里面的视图中添加了一个文件夹Book和Index.cshtml文件.但是我一直收到以下错误:
System.InvalidOperationException未创建在"〜/ Views/book/Index.cshtml"中找到的视图.
描述:
HTTP 500.Error处理请求.
细节:
非网络例外.异常来源(应用程序或对象的名称):System.Web.Mvc.异常堆栈跟踪:在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.IList
1[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:System.Web.Mvc中的0.System.Web.Mvc.Async.AsyncResultWrapper + WrappedAsyncVoid1[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中的Async.AsyncResultWrapper + WrappedAsyncResultBase 1 [System.Web.Mvc.Controller + ExecuteCoreState]:invoke_void_IAsyncResult_TState(System.IAsyncResult,System.Web.Mvc.Controller/ExecuteCoreState)1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase[TResult] .End()[0x00029] in:0,System.Web.Mvc.Async.AsyncResultWrapper.End [TResult](System.IAsyncResult asyncResult,System.Object标记)[0x00007] in:0,System.Web.Mvc.Async .AsyncResultWrapper.End(System.IAsyncResult asyncResult,System.Object标记)[0x00000] in:0,System.Web.Mvc.Controller.EndExecuteCore(System.IAsyncResult asyncResult)[0x00000] in:0,System.Web.Mvc. Controller.b__15(System.IAsyncResult asyncResult,System.Web.Mvc.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在System.Web.Mvc.Async.AsyncResultWrapper.End [TResult](System.IAsyncResult asyncResult,System.Object标记)[0x00007] in:0 at System.Web.Mvc.Async.AsyncResultWra pper.End(System.IAsyncResult asyncResult,System.Object标记)[0x00000] in:0,System.Web.Mvc.Controller.EndExecute(System.IAsyncResult asyncResult)[0x00000] in:0,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.EndInvokeVoidDelegate 1 [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在System.Web.Mvc.Async.AsyncResultWrapper.End(System.IAsyncResult asyncResult,System.Object标记)[0x00000] in:0 at System.Web.Mvc.MvcHandler.EndProcessRequest(System.IAsyncResult async)结果)[0x00000] in:0,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]在/ private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class1[System.Web.Mvc.MvcHandler+ProcessRequestState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.MvcHandler/ProcessRequestState)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid
我用Google搜索,人们说我必须确保views文件夹中的web.config如下:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Run Code Online (Sandbox Code Playgroud)
这是它与system.web.mvc的版本匹配,并查看system.web.mvc内部的版本是:
5.2.3
HomeController中的默认视图有效.我是第一次在Mac上试用ASP.net MVC而且在Windows上从未遇到过这种类型的问题.
欢迎任何帮助.
更新控制器代码:
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 ();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我猜测这个问题可能会发生,因为你正在手动创建所有的东西,而不是让模板引擎为你生成一些东西,就像在 Windows 中的 Visual Studio 中一样(个人没有尝试 Mac 版本,所以我不知道它到底是什么样子)。无论如何,假设您已经创建了控制器,然后创建了 Book 文件夹。但如果没有配置,也有一些东西需要手动配置,那就是当前控制器的路由。
您必须在RouteConfig文件类中设置路由逻辑,因此您将得到如下所示的内容:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Book" , action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
请参阅此问题以获取更多详细信息。
我猜的另一个版本是在 return 语句本身中设置视图名称,如下所示:
return View("Index")
Run Code Online (Sandbox Code Playgroud)
如果情况并非如此,请告诉我,以便我可以找到解决此问题的任何其他替代方案......
| 归档时间: |
|
| 查看次数: |
1137 次 |
| 最近记录: |