Asp.Net MVC3, returning success JsonResult

后端 未结 1 560
孤独总比滥情好
孤独总比滥情好 2020-12-03 06:04

I need to return JSON data that contain success value (true or false) also, it need to have result message too.

so I using Dictionary to contain data but when it ret

相关标签:
1条回答
  • 2020-12-03 06:37
    {"Success":"False","Message":"Error Message"}
    

    is valid JSON. You can check it here. in jsonlint.com

    You don't even need a Dictionary to return that JSON. You can simply use an anonymous variable like this:

    public ActionResult YourActionMethodName()
    {
       var result=new { Success="False", Message="Error Message"};
       return Json(result, JsonRequestBehavior.AllowGet);
    }
    

    to Access this data from your client, you can do this.

    $(function(){
       $.getJSON('YourController/YourActionMethodName', function(data) {
          alert(data.Success);
          alert(data.Message);
       });
    });
    
    0 讨论(0)
提交回复
热议问题