2016-09-15 33 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(); 
     } 
相關問題