2016-09-15 56 views
0

我有一个控制器结构,看起来像这样:MvcCodeRouting:“链接”的观点相同的路线作为控制器

[Controllers] 
    [Users] 
    [PlayersController.cs] 
    [ServicesController.cs] 

PlayersServices是两种不同类型的用户。

如果我像这样调用控制器:localhost:xxxx/Users/Players/正在调用索引,正如预期的那样,但是我的View未呈现。我的观点在~/Views/Users/Players/Index.cshtml之下,但ASP.NET并未在该文件夹下查找它。

我读,我应该使用EnableCodeRouting,但我不知道在何处以及如何使用它: https://github.com/maxtoroq/MvcCodeRouting/blob/master/docs/api/MvcCodeRouting/CodeRoutingExtensions/EnableCodeRouting_1.md

App_Start\RouteConfig.cs下添加了一个方法,但它从来没有被调用。

如何在不输入控制器中的视图链接的情况下,告诉MvcCodeRouting我的视图所在的位置?

I.e.我想用return View(vm)而不是return View("~/Views/Users/Players/index.cshtml")

回答

0

在global.asax.cs.Application_Start()补充一点:RegisterViewEngines(ViewEngines.Engines);

而且在同一个类中创建这种方法:

void RegisterViewEngines(ViewEngineCollection viewEngines) 
     { 

      // Call AFTER you are done making changes to viewEngines 
      viewEngines.EnableCodeRouting(); 
     }