FromBody值GET空

编程入门 行业动态 更新时间:2024-10-28 12:21:59
本文介绍了FromBody值GET空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是Asp.Net网络表单应用 - 这是我POST方法在我Apicontroller

公共无效后([FromBody]字符串值){}

我与小提琴手后处理。结果我这样做了实验。结果但事实并非如此。

有什么问题。结果你能帮忙吗?

我试过了,我失败了。

公共无效后(MyViewModel模型){   串AA = model.Value;}公共类MyViewModel{   公共字符串值{获得;组; }}

在提琴手:

请求正文:值=哈坎

解决方案

在提琴手POST正文有效载荷应该是:

= foo_bar这样的名称

而不是:

值= foo_bar这样的名称

这只是那些关于模型在Web API中结合奇怪的事情之一。如果你想支持值= foo_bar这样的名称在POST体内的有效载荷,你可以总是写一个视图模型:

公共类MyViewModel{    公共字符串值{获得;组; }}

,然后让你的方法采取这种观点模型参数:

公共无效后(MyViewModel模型){    ......与model.Value在这里工作如常}

This is Asp.Net Webform application This is my POST method in my Apicontroller

public void Post([FromBody]string value) { }

I'm with fiddler post process. I did so experiment. But it did not.

What is the problem. Can you help?

I've tried it, I've failed.

public void Post(MyViewModel model) { string aa = model.Value; } public class MyViewModel { public string Value { get; set; } }

In Fiddler:

Request Body: Value=hakan

解决方案

The POST body payload in Fiddler should be:

=foo_bar

instead of:

value=foo_bar

That's just one of those strange things about the model binding in the Web API. If you want to support value=foo_bar in the POST body payload you could always write a view model:

public class MyViewModel { public string Value { get; set; } }

and then have your method take this view model as parameter:

public void Post(MyViewModel model) { ... work with model.Value here as usual }

更多推荐

FromBody值GET空

本文发布于:2023-10-29 08:42:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539237.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:FromBody

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!