c# - ASP.NET MVC 4 call a controller method from another controller -


i stuck on issue. have 2 controllers, userscontroller , homecontroller trying call controller method userscontroller controller (homecontroller) doing this:

userscontroller userscontroller = new userscontroller(); 

but error: generate constructor stub in 'cthrc.roti.web.ui.controllers.userscontroller'

i not understand error.

here userscontroller:

using system; using system.io; using system.text; using system.collections.generic; using system.linq; using system.net; using system.net.http; using system.net.http.headers; using system.web; using system.web.http; using cthrc.roti.domain.api.services; using cthrc.roti.domain.model;  namespace cthrc.roti.web.ui.controllers {     public class userscontroller : apicontroller     {          protected readonly usersservice usersservice;          public userscontroller(usersservice usersservice)         {             usersservice = usersservice;         }          [httpget]         public dynamic get(int userid)         {             return usersservice.get(userid);         }     } } 

here homecontroller:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using webmatrix.webdata;  namespace cthrc.roti.web.ui.controllers {     public class homecontroller : controller     {         //         // get: /default/          public actionresult index()         {             if (!websecurity.isauthenticated)             {                 response.redirect("~/account/login");             }             userscontroller usercontroller = new userscontroller();             return view();          }      } } 

what have fix this? appreciated. thanks. reason trying because want data controller method.

your userscontroller not have parameterless constructor, expected call site.

you can add 1 this:

public userscontroller() { } 

otherwise, must provide usersservice parameter @ call site.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -