使用提取将表单提交到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 (将#修改为@)