How can I overload ASP.NET MVC Actions based on the accepted HTTP verbs?

前端 未结 4 1178
别那么骄傲
别那么骄傲 2021-01-01 12:14

Wanted to use the same URL for a GET/PUT/DELETE/POST for a REST based API, but when the only thing different about the Actions is which HTTP verbs it accepts, it considers t

4条回答
  •  失恋的感觉
    2021-01-01 12:36

    As a workaround you can add to one of the methods an extra argument with a default value, just to bypass the limitation and be able to build.

    Of course take in mind that this is not the most recommended way of doing things, and also you will have to make clear in your code (by the parameter name or via comments) that this is an extra argument just to allow it to build, and of course make sure that you have decorated your attributes correctly.

提交回复
热议问题