how to return multiple variables with jsonresult asp.net mvc3

前端 未结 6 1140
半阙折子戏
半阙折子戏 2020-12-24 09:15

How to return multiple variables on JsonResult method

for example i want to return this two variables:

string result = \"Successed\";
string ID = \"         


        
6条回答
  •  借酒劲吻你
    2020-12-24 10:01

    On your controller use something like this:

    var result = new { data= stuff, data2 = otherstuff };
    return Json(result, JsonRequestBehavior.AllowGet);
    

    If you are using .ajax() on your JavaScript you can use your data acessing like this:

    $.ajax(
                {
                    url: '/Controller/Method/',
                    type: 'POST',
                    data: 'data=' + data,
                    success: function (result) {
                        $('#id').html("");
                        $(result.data).appendTo('#id');
                        $('#id2').html("");
                        $(result.data2).appendTo('#id2');
                        $('#id').show();
                        $('#id2').show();
                    }
                });
    

提交回复
热议问题