如何调用使用属性路由为每个操作方法实现的Web Api,我想从我的客户端调用它并希望在请求的URL中传递Query参数(查询字符串)? [英] How to call the Web Api which is implemented with Attribute Routing for each action methods,i want to call it from my client and want to pass the Query parameters(Query String), in the requested url?

查看:64
本文介绍了如何调用使用属性路由为每个操作方法实现的Web Api,我想从我的客户端调用它并希望在请求的URL中传递Query参数(查询字符串)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计,



我已经为我的webapi中的每个操作方法实现了属性路由。

操作方法的示例是: -



Hi Folks,

I have implemented attribute routing for each of action methods in My webapi.
Example of action method is:-

[Route("api/DocumentApi/DeleteDocument/{fileInfoId}/{customerAccountName}")]
      [HttpDelete]
      public HttpResponseMessage DeleteDocument(int fileInfoId, string customerAccountName)
      {





// ***

// ***一些身体内容

// ***

}



现在我想从客户端示例(Fiddler Web调试器)或浏览器调用上述操作方法,并希望以下面的模式传递Url请求: -

http:// localhost:9791 / api / DocumentApi / DeleteDocument?fileInfoId = 12& customerAccountName =Manish



Cur我真的无法通过上面指定的url请求点击上面的操作方法。

但如果我使用如下所示的url模式: -

http:// localhost:9791 / api / DocumentApi / DeleteDocument / 12 / Manish [ ^ ],我可以点击上面的操作方法。但是对于我的项目要求,我只需要使用带有查询参数的Url。

请建议我的方法,如何实现这个目标?

任何回复都将不胜感激。



//***
//*** Some body contents
//***
}

Now i want to call the above action method from the client example( Fiddler Web debugger),or browser and want to pass the Url request in the below pattern:-
http://localhost:9791/api/DocumentApi/DeleteDocument?fileInfoId =12&customerAccountName="Manish"

Currently i am not able to hit the above action method by the above specified url request.
But if i use the url pattern like below:-
http://localhost:9791/api/DocumentApi/DeleteDocument/12/Manish[^], I am able to hit the above action method.But for my project requirement,I need to use the Url with query parameters only.
Please suggest me the approach,how to achieve this?
Any response will be greatly appreciated.

推荐答案

这篇关于如何调用使用属性路由为每个操作方法实现的Web Api,我想从我的客户端调用它并希望在请求的URL中传递Query参数(查询字符串)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆