为什么的ASP.NET Web API允许POST方法只有一个参数? [英] Why does ASP.NET Web API allow only one parameter for POST method?

查看:138
本文介绍了为什么的ASP.NET Web API允许POST方法只有一个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的ASP.NET Web API,我发现它有一个限制,这是非常烦人。它仅支持一个参数POST方法。 (在这里阅读更多:使用jQuery POST [FromBody]参数与Web API

I am new to ASP.NET Web API and I found that it has one limitation which is very annoying. It only supports one parameter to post method. (Read more here: Using jQuery to POST [FromBody] parameters to Web API)

从该链接,它看起来像他们这样设计它。它没有任何意义,我有这样奇怪的限制。

From that link, it seems like they design it this way. It doesn't make any sense to me to have such strange limitation.

如果有谁知道它为什么这样设计,请让我知道。

If anyone knows why it was designed this way, please let me know.

推荐答案

这是这样的HTTP工程。一个HTTP POST发送的身体。而作为一个网页API,该机构再度presents正在被张贴的资源对象。

This is the way HTTP works. An HTTP POST sends a body. And as a web api, that body represents the resource object that is being POSTed.

这是'对象',这是在POST可与许多属性一个复杂的对象,所以你可以创建一个包装对象重新present资源。它也可以是对象作为资源的集合的阵列

That 'object' which is in the POST can be a complex object with many properties so you can create a wrapper object to represent the resource. It can also be an array of objects as a collection of resources.

作为一个方面说明,如果你正在设计一个REST风格的Web API,那么它的最好员额资源(对象)的单个资源或阵到重新presents资源的集合的端点。例如,我的学生张贴到/ API /学生,并补充说,学生。

As a side note, if you're designing a RESTful web api, then it's desirable to POST an single resource or array of resources (objects) to an endpoint that represents a collection of resources. For example, I post a student to /api/students and it adds that student.

这篇关于为什么的ASP.NET Web API允许POST方法只有一个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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