Json.Net And ActionResult

前端 未结 2 531
醉话见心
醉话见心 2020-12-09 03:14

Im building a JObject myself and want to return it as ActionResult. I dont want to create and then serialize a data object

For example

public ActionR         


        
相关标签:
2条回答
  • 2020-12-09 03:51

    In case, if you take care of JSON Formatting , just return JSON Formatted string

    public string Test(string id)
    {
          var res = new JObject();
          JArray array = new JArray();
          array.Add("Manual text");
          array.Add(new DateTime(2000, 5, 23));
          res["id"] = 1;
          res["result"] = array;
          return YourJSONSerializedString;
    }
    

    else Use built in JsonResult(ActionResult)

        public JsonResult Test(string id)
        {
    
              return Json(objectToConvert);
        }
    
    0 讨论(0)
  • 2020-12-09 04:12

    You should just be able to do this in your action method:

    return Content( res.ToString(), "application/json" );
    
    0 讨论(0)
提交回复
热议问题