Asp.Net MVC3, returning success JsonResult

{"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);
   });
});

Leave a Comment