how to return multiple variables with jsonresult asp.net mvc3

前端 未结 6 1154
半阙折子戏
半阙折子戏 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 09:53

     public ActionResult YourAction()
     {
       var result=new { Result="Successed", ID="32"};
       return Json(result, JsonRequestBehavior.AllowGet);
     }
    

    EDIT : As per the comment "How to get this data in client"

    You can use getJSON from view to get this data like this

    $(function(){
       $.getJSON('YourController/YourAction', function(data) {
          alert(data.Result);
          alert(data.ID);
       });
    });
    

    Make sure you have jQuery loaded in your view for this code to work.

提交回复
热议问题