微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用提取将表单提交到MVC Action

如何解决使用提取将表单提交到MVC Action

我需要针对此特定操作使用提取,并且我尝试了多种方法,但无法使其正常工作。

在传递给操作的视图模型中,该值为null,并且如果我在操作中使用[FromBody],则会在控制台中抛出“ SyntaxError:JSON输入的意外末尾”,并且永远不会触发该操作

var TestData = { userviewmodel: { SubscriptionChoice: "2",BillingAddress: "test",PostCode: "test" } };

        fetch('/create-checkout-session',{
            method: 'POST',body: JSON.stringify(TestData)
        })

Userviewmodel :(除了这3个字段之外,还包含其他字段)

 public class Userviewmodel
 {
    public string SubscriptionChoice { get; set; }
    public string BillingAddress { get; set; }
    public string PostCode { get; set; }
 }

动作:

    [HttpPost("create-checkout-session")]
    public ActionResult CreateCheckoutSession([FromBody]Userviewmodel userviewmodel)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。