开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 8782|回复: 14

ASP.Net Core 使用DevExpress Bootstrap控件,求赞扬。

[复制链接]

0

精华

5

贡献

27

赞扬

帖子
10
软币
147
在线时间
14 小时
注册时间
2017-3-29
发表于 2018-12-10 10:47:47 | 显示全部楼层 |阅读模式
本帖最后由 isnb 于 2018-12-10 10:59 编辑

修改Startup.cs
[C#] 纯文本查看 复制代码
            services.AddMvc();            //使用DevExpress 服务
            services.AddDevExpressControls();         
            //使用Sqlite 数据库
            services.AddDbContext<DevExpressStarterProject.Models.NorthwindContext>(options => {
                options.UseSqlite(Configuration.GetConnectionString("NorthwindConnection"));


使用AJAX控件
在SampleController定义四个回调方法
[C#] 纯文本查看 复制代码
        public IActionResult GridViewPartial() {
            return PartialView(NorthwindContext.Products);
        }
        public IActionResult AddNewRow(Product product) {
            try {
                if(ModelState.IsValid) {
                    product.ProductID = NorthwindContext.Products.Max(p => p.ProductID) + 1;
                    NorthwindContext.Products.Add(product);
                    NorthwindContext.SaveChanges();
                }
            } catch(Exception e) {
                ViewData["error"] = e.Message;
            }
            return PartialView("GridViewPartial", NorthwindContext.Products);
        }
        public IActionResult UpdateRow(Product product) {
            try {
                if(ModelState.IsValid) {
                    NorthwindContext.Products.Update(product);
                    NorthwindContext.SaveChanges();
                }
            } catch(Exception e) {
                ViewData["error"] = e.Message;
            }
            return PartialView("GridViewPartial", NorthwindContext.Products);
        }
        public IActionResult DeleteRow(int productID = -1) {
            var product = NorthwindContext.Products
                .FirstOrDefault(i => i.ProductID == productID);
            try {
                NorthwindContext.Products.Remove(product);
                NorthwindContext.SaveChanges();
            } catch(Exception e) {
                ViewData["error"] = e.Message;
            }
            return PartialView("GridViewPartial", NorthwindContext.Products);
        }

将控件的Razor代码添加到创建的局部视图中。为新操作方法指定AJAX请求路由映射:
[C#] 纯文本查看 复制代码
@(Html.DevExpress()
    .BootstrapGridView<Product>("GridView")
    .KeyFieldName(m => m.ProductID)
    .Columns(columns => {
        columns.AddCommandColumn()
            .ShowEditButton(true)
            .ShowNewButtonInHeader(true)
            .ShowDeleteButton(true);
        columns.Add(m => m.ProductName);
        columns.Add(m => m.QuantityPerUnit);
        columns.Add(m => m.UnitPrice);
        columns.Add(m => m.UnitsInStock);
        columns
           .AddTextColumn()
           .FieldName("TotalPrice")
           .ReadOnly(true)
           .UnboundType(DevExpress.Data.UnboundColumnType.Decimal)
           .UnboundExpression("UnitPrice * UnitsInStock")
           .PropertiesTextEdit(properties => properties.DisplayFormatString("c"))
           .SettingsEditForm(editForm => editForm.Visible(false));
        columns.Add(m => m.Discontinued);
    })
    .Settings(settings => settings.ShowHeaderFilterButton(true))
    .EditErrorText(ViewData["Error"]?.ToString())
    .Routes(routes => routes
       .MapRoute(r => r
           .Action("GridViewPartial")
           .Controller("Sample"))
       .MapRoute(r => r
           .RouteType(GridViewRouteType.UpdateRow)
           .Action("UpdateRow")
           .Controller("Sample"))
       .MapRoute(r => r
           .RouteType(GridViewRouteType.AddRow)
           .Action("AddNewRow")
           .Controller("Sample"))
       .MapRoute(r => r
           .RouteType(GridViewRouteType.DeleteRow)
           .Action("DeleteRow")
           .Controller("Sample")))
    .Bind(Model))

自定义控件的外观
套件中的每个控件都有一个CssClasses方法,通过设置该方法改变控件外观
先添加样式代码
[size=1em]CSS

.my-button {    border-radius: 0;}
生成一个按钮控件并指定样式。
[size=1em]C#

@(Html.DevExpress()    .BootstrapButton("myButton")    .CssClasses(css => css.Control("my-button"))    .Text("My Button")

2.png


1.png

项目工程仅回复可见。项目依赖以下组件,自行安装。
  • ASP.Net Core 2.0
  • Bootstrap 3.3+ (including Bootstrap 4 Beta)
  • JQuery 2+
游客,如果您要查看本帖隐藏内容请回复





评分

参与人数 5贡献 +5 赞扬 +5 收起 理由
羽叶 + 5 + 1 感谢分享
play163 + 1 赞一个
3266252096 + 1 很给力
1077621683 + 1 赞一个
fidan + 1 感谢分享

查看全部评分

回复

使用道具 举报

0

精华

0

贡献

36

赞扬

帖子
28
软币
214
在线时间
12 小时
注册时间
2015-8-8
发表于 2018-12-27 16:31:30 | 显示全部楼层
从哪个版本支持ASP.Net Core 2.0
回复

使用道具 举报

0

精华

217

贡献

179

赞扬

赞助者组

Rank: 14Rank: 14Rank: 14Rank: 14

帖子
447
软币
3899
在线时间
240 小时
注册时间
2013-6-8
发表于 2019-1-5 12:01:13 | 显示全部楼层
从哪个版本支持ASP.Net Core 2.0
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
17
软币
112
在线时间
3 小时
注册时间
2018-7-4
发表于 2019-1-14 13:36:06 | 显示全部楼层
这个厉害,大声
回复

使用道具 举报

0

精华

0

贡献

18

赞扬

帖子
48
软币
403
在线时间
40 小时
注册时间
2018-5-15
发表于 2019-1-17 15:19:23 | 显示全部楼层
下来学习,感谢分享
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
5
软币
105
在线时间
3 小时
注册时间
2015-11-11
发表于 2019-2-1 15:36:08 | 显示全部楼层
很想看看楼主的实现方法,有demo吗
回复

使用道具 举报

0

精华

399

贡献

117

赞扬

正版授权组

Rank: 14Rank: 14Rank: 14Rank: 14

帖子
79
软币
666
在线时间
59 小时
注册时间
2017-9-15
发表于 2019-2-10 17:08:36 | 显示全部楼层
这个分享很不错,谢谢分享
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
17
软币
202
在线时间
16 小时
注册时间
2018-8-1
发表于 2019-5-21 22:34:45 | 显示全部楼层

从哪个版本支持ASP.Net Core 2.0
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
6
软币
96
在线时间
2 小时
注册时间
2018-5-5
发表于 2019-5-23 17:50:48 | 显示全部楼层
学习一下,顶啦
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
1
软币
76
在线时间
0 小时
注册时间
2019-9-1
发表于 2019-9-1 10:55:37 | 显示全部楼层

下来学习,感谢分享
回复

使用道具 举报

0

精华

0

贡献

18

赞扬

赞助者组

Rank: 14Rank: 14Rank: 14Rank: 14

帖子
18
软币
206
在线时间
10 小时
注册时间
2017-8-12
发表于 2020-8-13 15:15:56 | 显示全部楼层
看看111111111111111
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-26 14:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表