mvc 中JsonResult

前端之家收集整理的这篇文章主要介绍了mvc 中JsonResult前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

System.web.mvc.JsonResult 类


JsonResult :代码简洁,返回的是与拼接一样的 json格式的数据

[HttpPost]

public JsonResult GetStoried(int ID)

{

IList<BuildingNumber> buildingNumber = BuildingNumberBusiness.GetBuildingNumberByStreetalleyID( ID);
return Json(buildingNumber);

}



这种方式代码复杂,写起来花费时间相对也多些

[HttpPost] [HttpPost] public string GetStoried(int ID) { StringBuilder sbJson = new StringBuilder(); IList<BuildingNumber> buildingNumber = BuildingNumberBusiness.GetBuildingNumberByStreetalleyID( ID); sbJson.Append("["); sbJson.Append("{\"id\":\"" + "" + "\",\"text\":\"" + "--请选择--" + "\"},"); foreach (BuildingNumber list in buildingNumber) { sbJson.Append("{\"id\":\"" + list.BuildingNumberID.ToString() + "\",\"text\":\"" + list.BNName.Trim() + "\"},"); } sbJson.Remove(sbJson.Length - 1,1);//删除最后一个逗号 sbJson.Append("]"); return sbJson.ToString(); }

原文链接:https://www.f2er.com/json/290468.html

猜你在找的Json相关文章