none
Execute MVC3 Controller Action in the Console Application ?

    Question

  • Hi,

    Is possible to call a MVC 3 Controller Action from a Console Application. Is possible ?

    Please Help.


    rageshS

    Tuesday, November 13, 2012 6:22 AM

Answers

  • Friend,
      Yes possible.... If you add the reference of the applicaiton, you can call it as a method. For that you might need to create an object of controller and call the action method.

    This usually uses in Unit tests.


    -- Thanks Ajith R Nair

    • Marked as answer by RageshShiva Tuesday, November 13, 2012 10:22 AM
    Tuesday, November 13, 2012 8:40 AM
  • Just use create a HttpWebRequest then visit to that URL. Pass any parameter to it as if you would in normal web request.

    IMO, a MVC3 website is very similar to webservice sites that only allows HTTP GET and POST in that aspect. (Except that webservice require you to return XML, while you can return virtually everything with MVC)

    • Marked as answer by RageshShiva Tuesday, November 13, 2012 10:22 AM
    Tuesday, November 13, 2012 8:52 AM

All replies

  • Friend,
      Yes possible.... If you add the reference of the applicaiton, you can call it as a method. For that you might need to create an object of controller and call the action method.

    This usually uses in Unit tests.


    -- Thanks Ajith R Nair

    • Marked as answer by RageshShiva Tuesday, November 13, 2012 10:22 AM
    Tuesday, November 13, 2012 8:40 AM
  • Just use create a HttpWebRequest then visit to that URL. Pass any parameter to it as if you would in normal web request.

    IMO, a MVC3 website is very similar to webservice sites that only allows HTTP GET and POST in that aspect. (Except that webservice require you to return XML, while you can return virtually everything with MVC)

    • Marked as answer by RageshShiva Tuesday, November 13, 2012 10:22 AM
    Tuesday, November 13, 2012 8:52 AM
  • Thank you very much

    rageshS

    Tuesday, November 13, 2012 10:21 AM
  • Thank you very much, I use a WebRequest in my Console application.

    Thanks.


    rageshS

    Tuesday, November 13, 2012 10:23 AM