Display View in folder without Controller or Action in ASP.net MVC

后端 未结 4 1504
春和景丽
春和景丽 2021-01-15 17:29

I would like to display the view in the folder if no controller/action matches.

For example www.site.com/Home/Index, if I have the normal default route {controller}/

4条回答
  •  走了就别回头了
    2021-01-15 17:53

    I came across the same issue recently while developing AJAX web applications where most of the pages don't actually need a controller (all the data is returned via Web API calls).

    It seemed inefficient to have dozens of controllers all with a single action returning the view so I developed the ControllerLess plugin which includes a default view controller behind the scenes with a single action.

    If you create a controller for your view, then MVC will use that. However, if you create a view without a controller, the request is re-routed via the default plugin controller.

    It works with C# and VB.NET and us available at https://www.nuget.org/packages/ControllerLess

    The source code is also available on GitHub at https://github.com/brentj73/ControllerLess

提交回复
热议问题