惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 云龙

Unity4.0配置 win8.1安装出错解决方法之一 vs未能正确加载XX包的解决方法 下载android sdk ubuntu下安装与卸载软件方法 Ubuntu 安装杀毒软件防火墙 Ubuntu 图形处理软件 Ubuntu 下编译Android 源代码 ubuntu 安装配置 JDK7和Android Studio(apt-get方式) ununtu 下安装 Nvidia 显卡驱动 windows 8.1 在硬盘上创建扩展分区 (转)ASP.NET Identity登录原理 - Claims-based认证和OWIN (转)从Membership 到 .NET4.5 之 ASP.NET Identity (转)Asp.Net MVC中身份认证和授权 用JSON数据向已定义列的表格添加数据行 IIS7.0(虚拟机)发布MVC5程序出现Http403错误的解决方法. 如何避免MVC Model First 设计时添加的DataAnnotation被覆盖掉 移动路由表 cisco路由基于策略的路由选择
在MVC中动态读取JSON数据创建表格
云龙 · 2014-06-12 · via 博客园 - 云龙
//使用getJSON 

// ("@Url.Action("GetAllUsers","User")" ,json文件的路径.也可以是 /Member/User/GetAllUsers或者是GetAllUsers.json

$.getJSON("@Url.Action("GetAllUsers","User")", function (json) {

//初始化表格(可以是其它内容)
        var htmls = ['<table class="table">'];

//向表格添加标题行开始(横向)
        htmls.push('<tr>');

//遍历Json中k部分(json表示格式 k:v  ,如 UserName:admin)
        for (var title in json[0]) htmls.push('<td>' + title + '</td>');

//向表格添加标题行结束
        htmls.push('</tr><tbody>');

//循环读取Json数据,获取 V 部分 
        for (var i = 0; i < json.length; i++) {

//添加行开始
            htmls.push('<tr>');

//遍历每一个Json数据组,获取其中每一个value部分并添加.
            for (var v in json[i]) htmls.push('<td>' + json[i][v] + '</td>');

//添加行结束
            htmls.push('</tr>');
        }

//添加结束标记
        htmls.push('</tbody></table>');

//添加整个表格
        $('#userTable').html(htmls.join(''));
    });

//要添加表格的位置

<div id="userTable"></div>

JSON数据格式

[
    {
        "UserID":1,
        "UserName":"admin",
        "DisplayName":"管理员",
        "Email":"aaaaaaa@126.com"

    },{
       "UserID":2,
       "UserName":"test",
       "DisplayName":"测试",
       "Email":"ccccccc@126.com"
      }
]