Using WebAPI or MVC to return JSON in ASP.NET

前端 未结 6 403
闹比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:42

    I agree with Shaun Wilson's (top answer) answer but not sure why as I am just a bit confused and still trying to understand with the following (probably incorrect) premonition -

    • Use WebAPI Controller to deliver JSON data to the client so that the client can handle the view manipulation. This process doe NOT require a view but rather just a response back to whatever called the method (i.e. a javascript request) so that the client can handle any client-side manipulation.
    • Use MVC controller when you need to use the data to manipulate a view during or right after page_load (i.e. not for SPA apps).

    You see, I just don't know how I am incorrect here and am confused because the last line of Shaun's answer states "I use MVC controllers for handling basic browser routing and delivery of the SPA." - perhaps I do not fully know what a restful client is when I assumed it could be JavaScript method that receives an response in JSON form. this is the closest post in Stackoverflow that was remotely related as an answer to my question so I'm answering this post instead of possibly duplicating questions.

提交回复
热议问题