c# - CreatedAtRoute 与模板
问题描述
我有个问题。如何正确创建CreatedAtRoute
此方法:
HttpGet("exchangepoint")]
[ProducesResponseType(typeof(ExchangePointDto), 200)]
public async Task<IActionResult> GetExchangePoint(string name)
我试过这样:
result = CreatedAtRoute("GetExchangePoint",new { controller = "ShippingPlaceData", action = "GetExchangePoint", name = exchangePointToReturn.CustAccount }, exchangePointToReturn);
但它没有用。
编辑:
当我更改CreatedAtRoute
为CreatedAtAction
它开始工作但这是正确的方法吗?
解决方案
您可以使用该CreatedAtRoute
方法 - 当您使用属性路由时,您需要指定路由名称,如下所示。
[HttpGet("exchangepoint", Name = "GetExchangePoint")]
[ProducesResponseType(typeof(ExchangePointDto), 200)]
public IActionResult GetExchangePoint(string name)
{
}
而在 post 方法中,你可以这样使用。
result = CreatedAtRoute("GetExchangePoint",new { controller = "ShippingPlaceData", action = "GetExchangePoint", name = exchangePointToReturn.CustAccount }, exchangePointToReturn);
推荐阅读
- opengl - OpenGL 3.0 中没有光源的光
- python - 如何有一个行为类似于 bash 输入的 python 输入?
- amazon-web-services - CORS 策略已阻止从源“http://localhost:3000”获取 $AWS_LAMBDA_SITE 的访问权限
- cordova - 无法为 Ionic 4 应用程序创建/生成 .apk 和 .ipa 文件
- vue.js - Vue-ChartJS 没有反应
- python - 当我尝试计算奇数时,为什么有“无”?
- python - Sqlachemy 的问题。看不懂区别
- nginx - 如何查看一个 pod 是否超过了它的 CPU 限制?
- python - 不知道为什么:AttributeError: 'list' object has no attribute 'groupby'
- wordpress - 更新 wordpress 插件时如何使用 sftp 而不是 ftp?