2017-05-14 7 views
7

Ich erstellte eine ASP.net MVC-Anwendung mit Visual Studio Community Edition für Mac. Als ich lief, funktionieren die Standard HomeController und Index Ansicht gut. Dann habe ich einen BookController erstellt und in Ansichten einen Ordner Book und Index.cshtml hinzugefügt. Jedoch habe ich die folgende Fehlermeldung erhalte:ASP.net MVC Razor Ansicht auf Mono Mac

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

Beschreibung:

HTTP 500.Error processing request.

Details:

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.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[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.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[TResult].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in :0 at 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[System.Web.Mvc.Controller+ExecuteCoreState]:invoke_void_IAsyncResult_TState (System.IAsyncResult,System.Web.Mvc.Controller/ExecuteCoreState) at 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] 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+WrappedAsyncVoid 1[TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>: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.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.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[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

ich um gegoogelt und Leute sagten, ich sicher, dass die web.config Innenansichten machen Ordner ist wie folgt:

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

Das ist die Version von System.Web.Mvc entspricht und innerhalb System.Web.Mvc der Version suchen ist:

5.2.3

Und die Standardansicht in Homecontroller arbeitet. Ich versuche ASP.net MVC auf Mac zum ersten Mal und hatte nie diese Art von Problem unter Windows.

Jede Hilfe ist willkommen.

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(); 
    } 


} 
} 
+0

können Sie Controller-Code zeigen hier bitte! –

+0

@RajmondBurgaj yup Controller-Code bitte. Wir können nicht antworten, ohne Ihren Code zu debuggen. –

+0

Ich habe den Controller-Code hinzugefügt, Danke –

Antwort

1

Ich vermute, dass das Problem passieren könnte, weil Sie all die Dinge, manuell erstellen und nicht die Template-Engine etwas im Stich gelassen generieren für Sie in Visual Studio wie im Windows (persönlich hätte nicht versuchen, Mac-Version, so weiß ich nicht genau, wie es aussieht). Wie auch immer, nehmen wir an, Sie haben Ihren Controller und dann Book-Ordner erstellt. Aber es gibt auch etwas zu konfigurieren, wenn es nicht konfiguriert ist, und das ist Routing für den aktuellen Controller.

Sie haben Logik-Routing in RouteConfig Datei Klasse, so würden Sie so etwas wie dieses:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

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

Refere auf diese Frage für weitere Details here.

Eine andere Version, die ich denke, ist der Ansicht Namen in return-Anweisung selbst, wie Sie diese Einstellung:

return View("Index") 

Ist dies nicht der Fall ist, lassen Sie es mich wissen, damit ich andere Alternative für dieses Problem sehen ...

+0

Sehen Sie, es hat die Route config erstellt, und ASP.net stimmt mit dem Aktionsnamen überein, um eine Ansicht zu finden. Wenn Sie es sehen, heißt es, dass die Ansicht gefunden wurde, aber nicht erstellt wurde. –

+0

mit System.Web.Mvc; mit System.Web.Routing; Namespace TestMvcFromMac { public class RouteConfig { public static void RegisterRoutes (Routecollection Routen) { routes.IgnoreRoute ("{} Ressource .axd/{* pathInfo}"); routes.MapRoute ( Name: "Default", url: "{Controller}/{Aktion}/{id}", defaults: new {controller = "Home", action = "Index", id = UrlParameter .Optional} ); } } } –

+0

Auch für den Beweis des Konzepts, wenn es ein Routing-Problem, das ich wusste, ist es nicht, immer noch ich "Hallo Welt" String zurückgegeben und es richtig Router Router kein Fehler nur Rückkehr Ansicht wird nicht funktionieren –

1

Medium Visual Studio für Mac 2017 MVC Version 5.3.2

hatte ich genau das gleiche Problem. Meine Indexansichten funktionierten und andere Aktionen führten nicht zum selben Fehler. Ich weiß nicht warum, aber wenn ich ein Routenattribut manuell am Anfang der Aktion im Controller hinzufüge, waren es die Lösungen für meinen Fall

Schritte 1) füge folgende Zeile zum routeconfig hinzu.cs-Datei

routes.MapMvcAttributeRoutes(); 

2) hinzufügen Route-Attribut auf die Aktion manuell wie

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