How does a method in MVC WebApi map to an http verb?

后端 未结 2 1351
名媛妹妹
名媛妹妹 2020-11-27 02:56

In the 5-minute video at the following link, at the 1:10 mark, Jon Galloway says that adding a method called DeleteComment to his CommentsController controller class will by

2条回答
  •  甜味超标
    2020-11-27 03:13

    This comes up quite often. And there are different views on that. I personally have not subscribed to any particular idea for now but it seems the one with one-controller-per-resource to be the most popular among the REST community.

    So basically you can:

    1. Expose action in your route (Web API treats the word action similar to MVC) but this is generally not meant to be used.
    2. Define methods with different parameters as per this post
    3. As I said, most recommended is using one controller per resource. So even in the Web API sample, the controller for collection of an entity is different for the controller for the entity itself. Read this post by Rob Conery and here is Glenn's answer.

提交回复
热议问题