结束了天天加班的项目,项目虽然结束,但还是有点小问题,只能在后期优化当中完成了,本次做项目采用了,MVC、Webapi、Entityframework,在园了里看到了有关ABP的介绍,同样ABP也是最新技术集合,就加入了 ABP架构设计交流群 134710707,一起探讨、学习与进步。

  ABP的技术文档全是英文资料,不过现在不用担心了,群里的热心朋友已翻译成能看的懂语言了,详情 

  ABP 源代码地址 https://github.com/aspnetboilerplate 

  ABP的基本介绍就不讲了它是基于.net 4.5.1的,下载文档后自己了解吧,现在只讲解怎么用了

  公司的项目是基于Easyui的,因此Demo也是基于EasyUI的,ABP的返回值不能满足Easyui的datagrid请求与显示,对Abp源码进行了部分修改,才能正常使用,具体修改会一一列出,给需要的朋友一点帮助。

  ABP的请求值返回的对象属性首字母小写,这是因为默认的Json格式是 CamelCasePropertyNamesContractResolver  ,只要把相关代码修改为 

  对应的类名:AbpWebApiModule

private static void InitializeFormatters()
        {
            GlobalConfiguration.Configuration.Formatters.Clear();
            var formatter = new JsonMediaTypeFormatter();
            formatter.SerializerSettings.ContractResolver = new DefaultContractResolver();
            formatter.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            GlobalConfiguration.Configuration.Formatters.Add(formatter);
            GlobalConfiguration.Configuration.Formatters.Add(new PlainTextFormatter());
        }

  Easyui的Datagrid请求是通过URL传参数的,目前ABP不支持这种处理方法,因此只能自己在Controller里面写方法了,不能调用自动生成的WebAPi,多了一个步骤,下面是构造的分页类

public EasyUIPager GetPager(HttpRequestBase currentRequest)
        {
            EasyUIPager pager = new EasyUIPager();
            if (currentRequest.Form["page"] != null)
            {
                pager.CurrentPage = int.Parse(currentRequest.Form["page"]);
            }
            if (currentRequest.Form["rows"] != null)
            {
                pager.PageSize = int.Parse(currentRequest.Form["rows"]);
            }
            pager.SortCloumnName = currentRequest.Form["sort"];
            pager.SortOrder = currentRequest.Form["order"];
            pager.Filter = currentRequest.Form["filter"];
            return pager;
        }

 JS 请求调用代码

function GridInit() {
        //VE.LoodToolbar(); //加载权限
        datagrid = $("#datagrid").datagrid({
            url: VE.AppPath + '/User/Get',
            title: '用户信息',
            rownumbers: true,
            pagination: true,
            iconCls: VE.DatagridIconCls,
            height: VE.GridHeight,
            pageSize: VE.PageSize,
            pageList: VE.PageList,
            ctrlSelect:true,
            fitColumns: true,
            nowrap: false,
            border: true,
            idField: 'Id',
            sortName: 'Id',
            sortOrder: 'desc',
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'Id', title: 'Id', width: 80, sortable: true, hidden: true },
                { field: 'UserName', title: '用户名', width: 100, sortable: true },
                { field: 'Surname', title: '姓', width: 60, sortable: true },
                { field: 'Name', title: '名', sortable: true },
                { field: 'EmailAddress', title: '邮箱', sortable: true },
                { field: 'CreationTime', title: '创建时间', width: 140, sortable: true },
                { field: 'CreatorUserName', title: '创建人', width: 100, sortable: true },
                { field: 'LastModifierUserName', title: '最后更新人', width: 100, sortable: true },
                { field: 'LastModificationTime', title: '最后更新时间', width: 140, sortable: true, formatter: VE.FormatterDateTime },
                { field: 'IsActive', title: '状态', width: 45, sortable: true, formatter: VE.FormatterActive }
            ]],
            toolbar: [{
                iconCls: 'icon-add',
                text: '新增',
                handler: function () {
                    id = 0;
                    Save()
                }
            }, '-', {
                iconCls: 'icon-edit',
                text: '编辑',
                handler: function () {
                    id = VE.Edit("datagrid", VE.GridType_DataGrid)
                    if (id > 0) {
                        Save();
                    }
                }
            }, '-', {
                iconCls: 'icon-busy',
                text: '删除',
                handler: function () {
                    Delete();
                }
            }, '-', {
                iconCls: 'icon-unlock',
                text: '启用',
                handler: function () {
                    Active(true)
                }
            }, '-', {
                iconCls: 'icon-lock',
                text: '禁用',
                handler: function () {
                    Active(false)
                }
            }]
        });
    }
View Code

相关文章:

  • 2022-01-17
  • 2021-12-25
  • 2021-11-23
  • 2022-12-23
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2021-07-03
  • 2021-08-16
  • 2021-08-20
  • 2022-12-23
  • 2021-07-29
相关资源
相似解决方案