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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -