c# - Add existing Web Api project to existing Mvc project -


i have 2 projects in solution, mvc project , web api project. best way go utilizing web api project within mvc application?

options have come far:

  • deploy both projects , use helper class interact api (javascript or server side)
  • add reference web api project adds api functionality mvc project (not sure how integrate api project mvc project correctly, how this?)

if there better alternative please share.

in folder controllers have files this:

namespace beerdev.controllers {     public class homecontroller : controller     {         public actionresult index()         {             viewbag.title = "home";              return view();         }     } } 

and create folder called controllersapi files this:

namespace beerdev.controllersapi {     public class homecontroller : apicontroller     {         public ihttpactionresult get()         {             string beers;             using (streamreader sr = new streamreader(hostingenvironment.mappath("~/mockdata/beerfront.json")))             {                 beers = sr.readtoend();             }              if (string.isnullorempty(beers))             {                 return notfound();             }             return ok(beers);         }     } } 

in web api project there specialized kind of controller, still controller.

you can refer webap2_example.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -