How to return Json result from Controller Action Method

Manideepgoud
Posted by Manideepgoud under ASP.NET MVC category on | Points: 40 | Views : 570
We use JsonResult to get the json result values from controller action method

public JsonResult Output()
{
UserNamePasswordModel model = new UserNamePasswordModel();
{
UserName="DotNet";
Password="Funda";
}
return Json(model,JsonRequestBehavior.AllowGet);
}


Different ways to convert the model to Json string

System.Web.Script.Serialization.JavascriptSerialize serializer= new System.Web.Script.Serilization.JavaScriptSerialize();
return Json(Serializer.serialize(model).JsonRequestBehavior.AllowGet;)


Using NewtonSoft to convert model to Json string

return Json(NewtonSoft Json.JsonConvert.SerialzeObject(model), Json.RequestBehavior.AllowGet);

Comments or Responses

Login to post response