这是我的前缀属性
[RoutePrefix("news/farms")]
public class farmsController : ApiController我想删除一个基于farmid的行,但是我想要一个这样的url结构
/news/farms/{farmId}?version={Version}
我尝试过像下面的代码那样的路由url
[HttpDelete, Route("{farmId}?version={Version}", Name = "Deletefarm")]但这表明
The route template cannot start with a '/' or '~' character and it cannot contain a '?' character.请让我知道还有别的办法解决这个错误吗?
发布于 2017-10-23 12:21:33
在您的示例中设置RoutePrefix:
[RoutePrefix("news/farms")]
public class FarmsController : ApiController你的删除卫理公会:
[HttpDelete]
[Route("{farmId}")]
public void Delete(int farmId, string version)那么,这应该是可行的:
./新闻/农场/1?版本=myVersion
发布于 2017-10-23 11:20:26
为什么要尝试在路由中添加版本作为查询参数?在您的控制器路由中,这不是您想要的吗?
不过,这是否可行呢?
[HttpDelete]
public async Task<IActionResult> Delete(int id, [FromQuery] string version)
{
//...your code
}使用[FromQuery],可以指定您希望它从..。查询;)
发布于 2017-10-23 11:22:44
URI路径不能包含查询字符串,因此不允许查询字符串,请参阅- https://www.rfc-editor.org/rfc/rfc3986#section-3.3
你想要的答案是-
[HttpDelete]
public IActionResult DeleteFarm(int farmId, [FromQuery] string version)
{
//
}https://stackoverflow.com/questions/46888036
复制相似问题