Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.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
C# MVC BeginForm-从控制器返回三个不同的ajax文本字符串_C#_Jquery_Ajax_Asp.net Mvc - Fatal编程技术网

C# MVC BeginForm-从控制器返回三个不同的ajax文本字符串

C# MVC BeginForm-从控制器返回三个不同的ajax文本字符串,c#,jquery,ajax,asp.net-mvc,C#,Jquery,Ajax,Asp.net Mvc,我需要从控制器向视图发送3个变量(viewbags),当数据在beginform中提交时。由于下面的AJAX函数,目前我只能得到一个要发回的变量 JQUERY/AJAX function autosubmit() { $.ajax({ type: 'POST', url: this.action, data: $('form').serialize(), success: fu

我需要从控制器向视图发送3个变量(viewbags),当数据在beginform中提交时。由于下面的AJAX函数,目前我只能得到一个要发回的变量

JQUERY/AJAX

   function autosubmit() {


        $.ajax({
            type: 'POST',
            url: this.action,
            data: $('form').serialize(),
           success: function (result) {
                    $('#one').html(result); //ViewBag.one
                    $('#two').html(result); //ViewBag.two
                    $('#three').html(result); //ViewBag.three
                                     }

        });


    }
表格:


忘记ViewBag/ViewData。就好像它从未存在过一样

使用JSON:

[HttpPost]
public ActionResult Index(model stuff)
{
    var data = new 
    { 
        data1 = stuff.data1, 
        data2 = stuff.data2, 
        data3 = stuff.data3 
    };
    return Json(data);
}
然后消费:

$.ajax({
    type: 'POST',
    url: this.action,
    data: $('form').serialize(),
    success: function (result) {
        $('#one').html(result.data1);
        $('#two').html(result.data2);
        $('#three').html(result.data3);
    }
});
[HttpPost]
public ActionResult Index(model stuff)
{
    var data = new 
    { 
        data1 = stuff.data1, 
        data2 = stuff.data2, 
        data3 = stuff.data3 
    };
    return Json(data);
}
$.ajax({
    type: 'POST',
    url: this.action,
    data: $('form').serialize(),
    success: function (result) {
        $('#one').html(result.data1);
        $('#two').html(result.data2);
        $('#three').html(result.data3);
    }
});