c# - Overloading an api endpoint
问题描述
Is it possible to overload an api endpoint?
I would like the endpoint/route to be the exact same thing but the input parameters different. For example....
[HttpPost]
[Route("change-xxx")]
public async Task<IHttpActionResult> ChangeXxx(MyCPModel1 request)
And....
[HttpPost]
[Route("change-xxx")]
public async Task<IHttpActionResult> ChangeXxx(MyCPModel2 request)
I'm getting an "Multiple actions were found that match the request" error when I try it this way.
解决方案
Short answer -No, it is not possible to overload a Web API Endpoint. You can't have two endpoints with the exactly same path and verb. The error message "Multiple actions were found that match the request" confirms that.
推荐阅读
- python - 即使在无头模式下也会显示 Chromedriver.exe 窗口
- javascript - 防止自定义挂钩在每次重新渲染时重新初始化
- vue.js - 使用 vue-plotly 的 Vue.js 错误:fullLayout 未定义
- flutter - Flutter 应用的 ACH 支付处理(支持拆分支付)
- python - 将 Python ML 模型部署到 NodeJS Web 应用程序
- python - 当我在for中增加变量时,为什么迭代值没有发生任何事情?
- mysql - 是否有一个 mySQL 过程可以将重复的数据行合并为一个,然后允许我像处理一行一样操作该数据?
- jquery - 更改一个文本框值时使用哪个事件它应该更改 jquery 中另一个文本框中的相关值
- vb.net - 数据表中不需要的字符
- python - 从二进制矩阵构建图