0

如果我需要构建一个 Web 应用程序来实现与管理医疗医院机构相关的功能。该应用程序包括添加、更新、删除、搜索和检索患者、就诊等功能。

所以我很困惑在我的 ASP.NET MVC Web 应用程序中遵循哪种方法,或者在我的 asp.net MVC 中使用我的控制器类。

  1. 派生自 IController 以执行 CRUD 操作

或者

  1. 派生自 ApiController 以执行 CRUD 操作

第二个问题是否有一种方法可以取代另一种方法,每种方法相对于另一种方法的优点/缺点是什么?

4

2 回答 2

0

如果您要从控制器生成经典的 HTML 页面,请使用 MVC 页面。如果您想要返回给客户端的是某种序列化数据(XML、JSON、...),请使用 Web API 控制器,因为这些控制器更容易,例如内容协商。

另请参阅Web API 入门

于 2012-07-23T11:20:52.057 回答
0

You can absolutely use both. Nothing stops you to use good old Controller to do CRUD in JSON and MVC is capable of doing it. However, you do not get all the nice features of Web API such as content negotiation, message handlers, media type formatters, etc.

If you do not need any of Web API specific features, then use MVC. But on the long run, Web API will be a better investment as I believe adoption will rocket soon.

于 2012-07-23T12:15:11.560 回答