如何将参数从web api传递给控制器​​功能? [英] How to pass parameters from web api to controller function?

查看:77
本文介绍了如何将参数从web api传递给控制器​​功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我通过patameters从web api调用控制器功能。函数调用成功,但不传递参数。只要函数调用参数为null。我将为此做些什么?



我尝试过:



我检查了编码,数据类型,web api的一切。但它不能正常工作。请帮助我......

Hi,
I call controller function from web api with patameters. Function called successfully, but parameters are not passed. Whenever function called parameters are null. What i will do for that?

What I have tried:

I checked coding, datatype, web api everything. But it is not work properly. Please help me....

推荐答案

任何人都可以为您提供有关此问题(或其他问题)的任何帮助,您需要提供比您更好的信息。这里提供。提供的很多信息都不相关,因为据我所知,你在服务边界接收空值,所以下游代码不是问题的一部分 - 问题可能是你如何调用api - 你是否使用Rest测试了这个测试客户端(我使用的是Firefox插件和/或小提琴手)



您的消息是什么样的(我猜您在做帖子)什么是方法, URL,内容类型和正文...



例如



方法:POST URL:http: // loalhost:34715 / odata /产品

标题:内容类型:应用/ Json

身体:

{

ID:6,

描述:番茄,

SalePrice:15,

ProductGroup:蔬菜

}



提供这样的东西可以帮助别人帮助你 - 我怀疑这个问题导致问题的消息正文。



一条评论哟你的代码 - try catch块没有做任何事情 - 如果你删除它,代码的行为将与消费者看到的相同。除非你打算用它们做某事,否则不要捕获异常同样你不应该捕获一般例外。
For anybody to provide you with any help on this (or other issues), you will need to provide better information than you have provided here. A lot of the information provided is not relevant as I understand it you are receiving nulls at the service boundary so the downstream code is not part of the problem - the problem could be how you are invoking the api - have you tested this using a Rest test client (I use a Firefox plugin and/or fiddler)

What does your message look like (I am guessing you are doing a Post) what is the Method, URL, Content-Type and Body...

e.g.

Method : POST URL: http://loalhost:34715/odata/Products
Headers : Content-Type: Application/Json
Body :
{
"ID": 6,
"Description": "Tomato",
"SalePrice": "15",
"ProductGroup": "Vegetable"
}

Providing something like this may help others to help you - I suspect there is an issue with the body of your message that is causing the problem.

One comment on your code - the try catch block is not do anything - if you remove it the code will behave the same as seen from the consumer. Don't catch exceptions unless you are going to do something with them Equally you should not be capturing general exceptions.


这篇关于如何将参数从web api传递给控制器​​功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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