c# - .NET Core MVC generic controller views -


when trying create generic .net core mvc controller returns views, views aren't found(error message: "cannot resolve view details"). happening because, generic controller isn't tied specific view. view should picked based on t is. i've seen examples of in asp.net, i'm unable recreate in .net core.

is there way solve problem in .net core?

generic controller example:

public class controllerbase<t> : controller t : class {     private imanager<t> _manager;      public controllerbase( imanager<t> manager)     {         _manager = manager;     }      public async task<iactionresult> details(int? id)     {         if (id == null)         {             return notfound();         }          var result = await _manager.get(id);         return view(result);     } } 

as mentioned in comments can can specify view use via

return view("viewname", result); 

where viewname should adapted requirements (your question suggests maybe type name of type argument?

there may problem viewengine locating view depending on placed them , how controllers arranged. can around either specifying full path view:

return view("~/views/path/to/your/generic/viewname.cshtml", result); 

or extending search paths in viewengine mentioned here: can specify custom location "search views" in asp.net mvc?


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -