MVC4 Web API or MVC3 JsonResult

2019-06-22 09:27发布

I've seen a lot of arguments for why moving from WCF to Web API is a good move, but I haven't seen much on migrating from a controller with JsonResult actions to a Web API project. Can anyone provide the main benefits on switching to the Web API platform, or does it make sense to not migrate and stay on MVC3?

1条回答
神经病院院长
2楼-- · 2019-06-22 09:30

WebAPI provides a lot of stuff out of the box that you don't get with a standard JsonResult. For instance, WebAPI is aware of the content types the caller expects, and can return Json, or XML or other types as requested.

Another nice feature is that WebAPI is oData aware, and you can use standard oData HTTP commands to filter and perform other actions, all without your code needing to do anything specific.

WebAPI has tons of nifty features that make a nice webservice, without the overhead of a full WCF service or asmx.

If you're happy with a JsonResult though, there's no need to rewrite it.

查看更多
登录 后发表回答