public void GetArticles(HttpContext context) { List <Article> list = ArticleMgr.GetArticles(); //拼接json字符串 StringBuilder builder = new StringBuilder(); builder.Append("[");//[ foreach (Article item in list) { builder.Append("{");// { 'name':'jack','age':12 },{ 'name':'jack','age':12 },{ 'name':'jack','age':12 }, builder.AppendFormat("\"ID\":\"{0}\",\"Cate_Name\":\"{1}\",\"Title\":\"{2}\",\"Content\":\"{3}\",\"Update_Time\":\"{4}\",\"User_Name\":\"{5}\"", item.ID, item.Cate_Name, item.Title, item.Content, item.Update_Time.ToString(), item.User_Name); builder.Append("},"); } // [{ 'name':'jack','age':12 },{ 'name':'jack','age':12 },{ 'name':'jack','age':12 }, // [{ 'name':'jack','age':12 },{ 'name':'jack','age':12 },{ 'name':'jack','age':12 }] context.Response.Write(builder.ToString().Substring(0, builder.ToString().Length - 1) + "]"); // "123,"->"1234" /*string str = "123,"; * str.Substring(0, 3);//123 * str.Substring(0, str.Length - 1) + "4"; */ }
/// <summary> /// 查看文章页面 /// </summary> /// <returns></returns> public ActionResult ArticlesView() { List <Article> list = ArticleMgr.GetArticles(); ViewBag.ArticleList = list; return(View()); }
/// <summary> /// 获取文章列表 /// </summary> /// <returns></returns> public JsonResult GetArticles() { List <Article> list = ArticleMgr.GetArticles(); //默认的序列化,时间格式会有问题 //return Json(list); //string jsonStr = JsonConvert.SerializeObject(list, Config.FULL_DATE_FORMAT); //return Json(jsonStr); //使用layui table的方式 LayUITableModel res = new LayUITableModel(list.Count, list); return(Json(res)); }
/// <summary> /// 显示学术文章列表 /// </summary> /// <returns></returns> public ActionResult ArticleList() { var all = ArticleMgr.GetArticles(); return(View(all)); }