如何将参数传递到MVC控制器中?
将参数传递到ASP.NET核心MVC控制器的正确方法是什么?例如,我有一个具有以下签名的控制器:
[HttpPost]
public async Task<ActionResult<Input>> PostInput(Input input, string OutputPath)
注意:输入只是我完成的某些类。如何从我的React应用程序中调用此函数并传递参数。
先感谢您!
What is the proper way to pass parameters into Asp.Net core MVC controllers. For example, I have a controller with the following signature:
[HttpPost]
public async Task<ActionResult<Input>> PostInput(Input input, string OutputPath)
Note: Input is just some class I made. How do I call this function from my react application and pass in the parameters.
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试通过查询字符串传递
outputpath
,然后通过表单传递输入
。
输入
结果:

You can try to pass
OutputPath
via query string,and passInput input
via form.Here is a demo:Input:
action:
request:


result:
Also,you can pass both

OutputPath
andInput input
via query string:您不能在
[来自Body]
[from form from] 中都将两个参数一起传递在一起] 上下文。因此,要么您必须将输出路径移至类中,要么将类属性作为方法参数传递。您可以在在这里官方文件。有效的签名格式:1与方法参数时尚:
输出1:
有效的签名格式:2具有类时尚:
模型应为:
输出2:
net/lmzf1.gif“ rel =“ nofollow noreferrer 还有任何其他问题,您可以看一下我们的
。
You cannot pass two parameter together either in
[FromBody]
neither in[FromForm]
because its not allowed to pass more than one parameter within one action specially for[FromBody]
context . So either you have to move the OutputPath into the class or pass the class property as method argument. You could get more details on the official document here.Valid Signature Format: 1 With Method Argument fashion:
Output 1:
Valid Signature Format: 2 With Class Fashion:
Model should be:
Output 2:
Note: if you still have any further concern you could have a look our
official document here
.