View ASP.NET MVC Razor on Mono Mac

I created an ASP.net MVC application using Visual Studio Community Edition for Mac. When I launched the standard view of HomeController and Index, the work is fine. Then I made a BookController and inside the views I added the Book folder and Index.cshtml file. However, I keep getting the following error:

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

Description:

Request HTTP request 500.Error.

More details:

An exception without websites. Original 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] at: 0 on System.Web.Mvc.ViewResultBase.ExecuteResult (System. Web.Mvc.ControllerContext context) [0x00080] at: 0 on System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] at: 0 .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.IList 1 filter [T], System.Intr.v. ltExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0009b] at: 0 on System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters (System.Context.esblon .Generic.IList 1[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+WrappedAsyncResult :. 1[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+WrappedAsyncResult > b__1e (System.IAsyncResult asyncResult) [0x00041] in <cc73190bab9d435c831510ff295c572a>: 1[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+WrappedAsyncResult 1 [TResult] .CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper + WrappedAsyncResultBase 1[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.EndInvokeVoidDelegate 1[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.EndInvokeVoidDelegate 1 [System.Web.Mvc.Controller + ExecuteCoreState]: invoke_void_IAsyncResult_TState. SystemVate.Itate.Tec.leTate.Tec.tel.tate.tate. in System.Web.Mvc.Async.AsyncResultWrapper + WrappedAsyncVoid 1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase [TResult] .END () [0x00029] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper.End [TResult] (System.IAsyncResult asyncResult, tag System.Object) [0x00007] at: 0 on System.Web. Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, System.Object tag) [0x00000] at: 0 on System.Web.Mvc.Controller.EndExecuteCore (System.IAsyncResult asyncResult) [0x00000] on: 0 .Mvc.Controller.b__15 (System.IAsyncResult asyncResult, System.Web.Mvc.Controller controller) [0x00000] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper + WrappedAsyncVoid 1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase 1 [TResult] .END () [0x00029] at: 0 on System.Web.Mvc.Resultc.AsynesAs ] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper.End (System.IAsyncResult asyncResult, Sys tag tem.Object) [0x00000] at: 0 on System.Web.Mvc.Controller.EndExecute (System.IAsyncResult asyncResult) [0x00000] at: 0 on System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController .EndExecute (System.IAsyncResult asyncResult) [0x00000] at: 0 on System.Web.Mvc.MvcHandler.b__5 (System.IAsyncResult asyncResult, System.Web.Mvc.MvcHandler + ProcessRequestState innerState) [0x00000 at] shell delegate) System.Web.Mvc.Async.EndInvokeVoidDelegate 1[System.Web.Mvc.MvcHandler+ProcessRequestState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.MvcHandler/ProcessRequestState)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid
1[System.Web.Mvc.MvcHandler+ProcessRequestState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.MvcHandler/ProcessRequestState)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid
1[System.Web.Mvc.MvcHandler+ProcessRequestState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.MvcHandler/ProcessRequestState)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid
1 [TState] .CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper + Wrapped ) [0x00029] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper.End [TResult] (System.IAsyncResult asyncResult, tag System.Object) [0x00007] at: 0 on System.Web.Mvc.Async.AsyncResultWrapper. End (System.IAsyncResult asyncResult, tag System.Object) [0x00000] at: 0 on System.Web.Mvc.MvcHandler.EndProcessRequest (System.IAsyncResult asyncResult) [0x00000] at: 0 on System.Web.Mvc.MvcHler .Web.IHttpAsyncHandler.EndProcessRequest (Result of System.IAsyncResult) [0x00000] at: 0 on System.Web.HttpApplication.async_handler_complete_cb (System.IAsyncResult ar) [0x00015] in / Private / TMP-bock / mon-2017 / bmp-bock / bmp 2017-02 / profiles / mono-mac-xamarin / build root / mono-x86 / mcs / class

I googled around and people said that I have to make sure the web.config folder inside the views is as follows:

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

That is, it corresponds to the version of system.web.mvc and looks inside system.web.mvc:

5.2.3

And the default view in HomeController works. This is the first time I am running ASP.net MVC on a Mac and have never encountered such problems on Windows.

Any help is appreciated.

Update controller code:

 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 (); } } } 
+7
c # visual-studio asp.net-mvc asp.net-mvc-4 macos
source share
2 answers

I assume that the problem may arise because you create all the data manually and do not allow the template engine to generate something for you, like in a visual studio in windows (I have not personally tried the Mac version, so I don’t know for sure what it looks like). In any case, let's assume that you created your controller and then the Book folder. But there is something to configure manually if it is not configured, and this is routing for the current controller.

You must set the routing logic in the RouteConfig class, so you will have something like this:

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Book" , action = "Index", id = UrlParameter.Optional } ); 

Refer to this question for more details here .

Another version, I suppose, sets the view name inside the return statement itself as follows:

 return View("Index") 

If this is not the case, please let me know, so I can see any other alternative for this problem ...

+1
source share

Visual Studio for Mac 2017 MVC Version 5.3.2

I had the same problem. My pointers were working, and the other actions were not, which gave the same error. I don’t know why, but when I add the route attribute manually at the beginning of the action in the controller, these were solutions for my case

steps 1) add the following line to the routeeconfig.cs file

  routes.MapMvcAttributeRoutes(); 

2) add the route attribute to the action manually as

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

All Articles