EasyUI 之 DataGrid的两种赋值方法
方法一:使用ViewData赋值
首先,我们创建一个User的实体类
- public class User
- {
- public string UserID;
- public string UserName;
- public string Sex;
- }
然后,我们在Action中添加假数据,并将假数据放到ViewData中
- public ActionResult test()
- {
- List<User> listUser = new List<User>();
- listUser.Add(new User
- {
- UserID = "001",
- UserName = "呵呵",
- Sex = "男"
- });
- listUser.Add(new User
- {
- UserID = "002",
- UserName = "哈哈",
- Sex = "女"
- }); listUser.Add(new User
- {
- UserID = "003",
- UserName = "嘿嘿",
- Sex = "男"
- });
- ViewData["listUser"] = listUser;
- return View();
- }
最后,我们在前台用ViewData给DataGrid赋值
- <div>
- <table id="dg" class="easyui-datagrid" style="width: 600px; height: 300px" >
- <thead>
- <tr>
- <th data-options="field:'UserID',width:148,sortable:true">ID</th>
- <th data-options="field:'UserName',width:148,sortable:true">姓名</th>
- <th data-options="field:'Sex',width:148,sortable:true">性别</th>
- </tr>
- </thead>
- @foreach (ITOO.EvaluationUI.Models.User enUser in ViewData["listUser"] as List<ITOO.EvaluationUI.Models.User>)
- {
- <tr>
- <td>@enUser.UserID </td>
- <td>@enUser.UserName </td>
- <td>@enUser.Sex </td>
- </tr>
- }
- </table>
- </div>
方法二:使用url赋值
首先,我们在前台的DataGrid中加上URL属性
- <div>
- <table id="dg" class="easyui-datagrid" style="width: 600px; height: 300px" >
- <thead>
- <tr>
- <th data-options="field:'UserID',width:148,sortable:true">ID</th>
- <th data-options="field:'UserName',width:148,sortable:true">姓名</th>
- <th data-options="field:'Sex',width:148,sortable:true">性别</th>
- </tr>
- </thead>
- </table>
- </div>
- <!--datagrid基本设置-->
- <script type="text/javascript">
- $(function () {
- $('#dg').datagrid({
- title: '测试表格',
- url: "/EvaluationSituation/jsonTest",
- pagination: true,//显示分页工具栏
- });
- });
- </script>
然后,我们在相应的控制器中添加一个得到json数据的方法
- public JsonResult jsonTest()
- {
- List<User> listUser = new List<User>();
- listUser.Add(new User {
- UserID ="001",
- UserName="呵呵",
- Sex ="男"
- });
- listUser.Add(new User
- {
- UserID = "002",
- UserName = "哈哈",
- Sex = "女"
- }); listUser.Add(new User
- {
- UserID = "003",
- UserName = "嘿嘿",
- Sex = "男"
- });
- JsonResult jsonUser = new JsonResult();
- jsonUser = Json(listUser);
- return jsonUser;
- }
上面介绍的两种方法能够解决我们给DataGrid赋值的问题,其中方法二里面除了将List集合转换成Json对象以外,我们还可以自己写一个方法将List转换成Json格式的字符串,这样也可以给DataGrid赋值。虽然我们能够赋值,但是这样做也有一些其他的问题,比如说怎么它的分页怎么实现,这就是下一节将要讲解的内容
EasyUI 之 DataGrid的两种赋值方法的更多相关文章
- Java中String对象两种赋值方式的区别
本文修改于:https://www.zhihu.com/question/29884421/answer/113785601 前言:在java中,String有两种赋值方式,第一种是通过“字面量”赋值 ...
- 关于String的两种赋值方式
String的两种赋值是不同的,String str1=“hello”,指向堆内存中的"hello",而String str2=new String("hello&quo ...
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结
史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...
- bind()函数的深入理解及两种兼容方法分析
在JavaScript中,bind()函数仅在IE9+.Firefox4+.Chrome.Safari5.1+可得到原生支持.本文将深入探讨bind()函数并对两种兼容方法进行分析比较.由于本文将反复 ...
- 菜鸡的Java笔记 第十三 String 类的两种实例化方法
String 类的两种实例化方法 String 类的两种实例化方式的区别 String 类对象的比较 Stirng 类对象的使用分析 /* 1.String 类的两种实例化方式的区别 ...
- angular2系列教程(十)两种启动方法、两个路由服务、引用类型和单例模式的妙用
今天我们要讲的是ng2的路由系统. 例子
- git两种合并方法 比较merge和rebase
18:01 2015/11/18git两种合并方法 比较merge和rebase其实很简单,就是合并后每个commit提交的id记录的顺序而已注意:重要的是如果公司用了grrit,grrit不允许用m ...
- easyui里弹窗的两种表现形式
easyui里弹窗的两种表现形式 博客分类: jQueryEasyUi 1.主JSP页面中描绘弹窗 <div id="centerDiv" data-options= ...
- 两种Ajax方法
两种Ajax方法 Ajax是一种用于快速创建动态网页的技术,他通过在后台与服务器进行少量的数据交换,可以实现网页的异步更新,不需要像传统网页那样重新加载页面也可以做到对网页的某部分作出更新,现在这项技 ...
随机推荐
- bzoj5157: [Tjoi2014]上升子序列(树状数组LIS)
5157: [Tjoi2014]上升子序列 题目:传送门 题解: 学一下nlogn的树状数组求最长上生子序列就ok(%爆大佬) 离散化之后,用一个数组记录一下,直接树状数组做 吐槽:妈耶...一开始不 ...
- GitHub客户端和Shell的基本操作和理解
GitHub客户端和Shell指令的简单实用 客户端操作, web端操作, shell指令操作. 掌握了这三种操作,基本上就可以很好的运用gitHub了. 创建项目, 可以通过web端进行创建. 可以 ...
- NOIP 2012 T2 国王游戏 (贪心+高精)
思路: 呃呃网上那么多题解写得都不错-.. 就是高精 巨坑... 这里展出的是任氏高精(纯自己yy滴) //By SiriusRen #include <cstdio> #include ...
- (转载)打开一个本地apk进行安装
1 2 3 4 5 6 Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); File file = new File ...
- (转载)所有分类 > 开发语言与工具 > 移动开发 > Android开发 Android中的Service:默默的奉献者 (1)
前言 这段时间在看一些IPC相关的东西,这里面就不可避免的要涉及到service,进程线程这些知识点,而且在研究的过程中我惊觉自己对这些东西的记忆已经开始有些模糊了——这可要不得.于是我就干脆花了点心 ...
- double int 类型的区别
内部组织格式不同: po [NSString stringWithFormat:@"%d", f] 107886912 (lldb) po [NSString stringWith ...
- 手把手教你如何新建scrapy爬虫框架的第一个项目(上)
前几天给大家分享了如何在Windows下创建网络爬虫虚拟环境及如何安装Scrapy,还有Scrapy安装过程中常见的问题总结及其对应的解决方法,感兴趣的小伙伴可以戳链接进去查看.关于Scrapy的介绍 ...
- Spring Framework 开发参考手册中文(在线HTML)
https://blog.csdn.net/zfrong/article/details/3971722
- document.body
比如document.body,最好是写成document.getElementsByTagName("body")[0];
- pyinstall 常见错误
字符编码错误: https://blog.csdn.net/weixin_42426496/article/details/81102665 https://blog.csdn.net/qq_4206 ...