Using WebAPI or MVC to return JSON in ASP.NET

前端 未结 6 401
闹比i
闹比i 2020-12-04 07:50

I\'m building an ASP.NET MVC application that is client-script heavy, it will use JSON and jQuery to manipulate the DOM.

My understanding is both Web API Con

6条回答
  •  一整个雨季
    2020-12-04 08:28

    WebAPI is for making an API. If you want someone to be able to consume your API in XML, JSON, etc. You can make a web api.

    In your case you only need to talk to client in JSON.

    Even though your website is mostly client script driven you would still be using ASP.NET MVC Controller right? And since you may have already logically divided your controllers based on entities then it make sense to add those json serving methods in it as opposed to making another class specifically for web api.

    So for your particular situation (if i understand correctly), I would stick with Controllers.

提交回复
热议问题