Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用AJAX将表单传递给控制器MVC_Jquery_Asp.net Mvc - Fatal编程技术网

Jquery 使用AJAX将表单传递给控制器MVC

Jquery 使用AJAX将表单传递给控制器MVC,jquery,asp.net-mvc,Jquery,Asp.net Mvc,想知道如何使用AJAX将表单传递给控制器MVC。 我尝试过各种方法,比如JSON.stringify,但没有任何方法适合我。我的输入名称是一个数组。例如,已接收[0]。basketball,已接收[1]。basketball,已接收[2]。basketball。所以列表应该有Count=3,但列表一直为空 更新:包括表单id public ActionResult Validate(List<Stuff> item) { //null } @using (Html.Begin

想知道如何使用AJAX将表单传递给控制器MVC。 我尝试过各种方法,比如JSON.stringify,但没有任何方法适合我。我的输入名称是一个数组。例如,已接收[0]。basketball,已接收[1]。basketball,已接收[2]。basketball。所以列表应该有Count=3,但列表一直为空

更新:包括表单id

public ActionResult Validate(List<Stuff> item)
{
   //null
}

@using (Html.BeginForm("Test", "Test", FormMethod.Post, new { id = "form" }))
{
    <input name="Receive[0].basketball" id="basketball' + x + '" value=""/>
    <input name="Receive[0].ball" id="ball' + x + '" value=""/>
    <input name="Receive[1].basketball" id="basketball' + x + '" value=""/>
    <input name="Receive[1].ball" id="ball' + x + '" value=""/>
}

$.ajax({
        type: "POST",
        url: "../../Validate",
        dataType: 'json',
        data: {
            item:  $('#form').serializeArray(),
        },
        success: function (result) {

        }
    });
公共操作结果验证(列表项)
{
//空的
}
@使用(Html.BeginForm(“Test”、“Test”、FormMethod.Post、new{id=“form”}))
{
}
$.ajax({
类型:“POST”,
url:“../Validate”,
数据类型:“json”,
数据:{
项:$('#form').serializeArray(),
},
成功:功能(结果){
}
});

您可以在此处使用
serialize()

var datastring = $("#form").serialize();
$.ajax({
        type: "POST",
        url: "../../Validate",
        dataType: 'json',
        data: datastring,
        success: function (result) {

        }
    });

它有什么作用?(您的
#表单
是您表单的正确ID吗?您的问题没有包括它)您需要显示您的
资料
模型。您的
名称
属性与
列表项
参数没有关系
 var form = $('#form');
 var formData = $(form).serialize();

 $.ajax({
            type: 'POST',
            url: $(form).attr('action'),
            data: formData,
            success: function (result) 
        {

    }
});