BootstrapBlazor 智能生成神器(一)AutoGenerateColumnAttribute 特性介绍
原文连接:https://www.cnblogs.com/ysmc/p/16074645.html
BootstrapBlazor 官网地址:https://www.blazor.zone
介绍
BootstrapBlazor 中的 Table 组件、EditorForm 表单组件、ValidateForm 表单组件 等等组件,都具有根据实体类自动生成相应功能的能力,而这里起到关键作用的就是 AutoGenerateColumnAttribute,从命名可以得知,这是一个特性,让我们来看看他支持哪些功能吧。
| 属性 | 类型 | 作用 | 说明 |
| Order | int | 获得/设置 显示顺序 |
规则如下: >0时排前面,1,2,3... =0时排中间(默认) <0时排后面,...-3,-2,-1 |
| Ignore | bool | 获得/设置 是否忽略 | 默认为 false 不忽略 |
| DefaultSort | bool | 获得/设置 是否为默认排序列 | 默认为 false |
| SkipValidate | bool | 获得/设置 是否不进行验证 | 默认为 false |
| IsReadonlyWhenAdd | bool | 获得/设置 新建时此列只读 | 默认为 false |
| IsReadonlyWhenEdit | bool | 获得/设置 编辑时此列只读 | 默认为 false |
| DefaultSortOrder | SortOrder | 获得/设置 是否为默认排序规则 | 默认为 SortOrder.Unset |
| Width | int | 获得/设置 列宽 | |
| Fixed | bool | 获得/设置 是否固定本列 | 默认 false 不固定 |
| Visible | bool | 获得/设置 列是否显示 | 默认为 true 可见的 |
| CssClass | string? | 获得/设置 列 td 自定义样式 | 默认为 null 未设置 |
| ShownWithBreakPoint | BreakPoint | 获得/设置 显示节点阈值 | 默认值 BreakPoint.None 未设置 |
| FormatString | string? | 格式化字符串 | 如时间类型设置 yyyy-MM-dd |
| PlaceHolder | string? | 获得/设置 placeholder 文本 | 默认为 null |
| Formatter | Func<object?, Task<string>>? | 获得/设置 列格式化回调委托 | |
| HeaderTemplate | RenderFragment<ITableColumn>? | 获得/设置 表头模板 | |
| ComponentType | Type? | 获得/设置 组件类型 | 默认为 null |
| Template | RenderFragment<object>? | 获得/设置 显示模板 | |
| Step | object? | 获得/设置 步长 | 默认为 1 |
| Rows | int | 获得/设置 Textarea 行数 | |
| PropertyType | Type? | 获得 属性类型 | |
| Text | string? | 获得/设置 当前属性显示文字 列头或者标签名称 |
实战
下面我们来看看它在 ValidateForm 组件 与 EditorForm 组件中的表现
实体类 Foo.cs
1 public class Foo
2 {
3 /// <summary>
4 ///
5 /// </summary>
6 [Key]
7 [Display(Name = "主键")]
8 [AutoGenerateColumn(Ignore = true)]
9 public int Id { get; set; }
10
11 /// <summary>
12 ///
13 /// </summary>
14 [Required(ErrorMessage = "{0}不能为空")]
15 [AutoGenerateColumn(Order = 10, Filterable = true, Searchable = true)]
16 [Display(Name = "姓名")]
17 public string? Name { get; set; }
18
19 /// <summary>
20 ///
21 /// </summary>
22 [AutoGenerateColumn(Order = 1, FormatString = "yyyy-MM-dd", Width = 180)]
23 [Display(Name = "日期")]
24 public DateTime? DateTime { get; set; }
25
26 /// <summary>
27 ///
28 /// </summary>
29 [Display(Name = "地址")]
30 [Required(ErrorMessage = "{0}不能为空")]
31 [AutoGenerateColumn(Order = 20, Filterable = true, Searchable = true)]
32 public string? Address { get; set; }
33
34 /// <summary>
35 ///
36 /// </summary>
37 [Display(Name = "数量")]
38 [Required]
39 [AutoGenerateColumn(Order = 40, Sortable = true)]
40 public int Count { get; set; }
41
42 /// <summary>
43 ///
44 /// </summary>
45 [Display(Name = "是/否")]
46 [AutoGenerateColumn(Order = 50)]
47 public bool Complete { get; set; }
48
49 /// <summary>
50 ///
51 /// </summary>
52 [Required(ErrorMessage = "请选择学历")]
53 [Display(Name = "学历")]
54 [AutoGenerateColumn(Order = 60)]
55 public EnumEducation? Education { get; set; }
56
57 /// <summary>
58 ///
59 /// </summary>
60 [Required(ErrorMessage = "请选择一种{0}")]
61 [Display(Name = "爱好")]
62 [AutoGenerateColumn(Order = 70, Editable = false)]
63 public IEnumerable<string> Hobby { get; set; } = new List<string>();
64 }
页面 Foo.razor
1 <ValidateForm Model="@ValidateModel">
2 <EditorForm TModel="Foo">
3 <FieldItems>
4 <EditorItem @bind-Field="@context.DateTime" Readonly="true" />
5 <EditorItem @bind-Field="@context.Hobby" Items="@Hobbys" />
6 </FieldItems>
7 <Buttons>
8 <Button ButtonType="ButtonType.Submit" Icon="fa fa-save" Text='提交' />
9 </Buttons>
10 </EditorForm>
11 </ValidateForm>
呈现效果

同时支持根据实体类属性的特性进行表单验证,非常的好用

BootstrapBlazor 智能生成神器(一)AutoGenerateColumnAttribute 特性介绍的更多相关文章
- Bootstrap Blazor Table 组件(三)智能生成
原文链接:https://www.cnblogs.com/ysmc/p/16201153.html Bootstrap Blazor 官网地址:https://www.blazor.zone 有了解过 ...
- Xcode9新特性介绍-中文篇
背景: Xcode 9 新特性介绍: 1.官方原文介绍链接 2.Xcode9 be ta 2 官方下载链接 本文为官方介绍翻译而来,布局排版等都是按照官方布局来的. 与原文相比,排版上基本还是熟悉的配 ...
- Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性
Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性 Apache hadoop 项目组最新消息,hadoop3.x以后将会调整方案架构,将Mapreduce 基于内存+io+ ...
- jdk7和8的一些新特性介绍
jdk7和8的一些新特性介绍 本文是我学习了解了jdk7和jdk8的一些新特性的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwor ...
- ArcGIS 10.3 for Desktop新特性介绍
ArcGIS 10.3是一个完整公布的ArcGIS平台,它包含新的产品(ArcGIS Pro),针对10.2版本号产品进行了功能增强和稳定性的改进. ArcGIS 10.3 for Server新特性 ...
- .NET Standard 2.0 特性介绍和使用指南
.NET Standard 2.0 发布日期:2017年8月14日 公告原文地址 前言 早上起来.NET社区沸腾了,期待已久的.NET Core 2.0终于发布!根据个人经验,微软的产品一般在2.0时 ...
- .Net大局观(2).NET Core 2.0 特性介绍和使用指南
.NET Core 2.0发布日期:2017年8月14日 前言 这一篇会比较长,系统地介绍了.NET Core 2.0及生态,现状及未来计划,可以作为一门技术的概述来读,也可以作为学习路径.提纲来用. ...
- .Net Core 2.0生态(4):Entity Framework Core 2.0 特性介绍和使用指南
前言 这是.Net Core 2.0生态生态介绍的最后一篇,EF一直是我喜欢的一个ORM框架,随着版本升级EF也发展到EF6.x,Entity Framework Core是一个支持跨平台的全新版本, ...
- .Net Core 2.0 生态(2).NET Core 2.0 特性介绍和使用指南
.NET Core 2.0发布日期:2017年8月14日 前言 这一篇会比较长,介绍了.NET Core 2.0新特性.工具支持及系统生态,现状及未来计划,可以作为一门技术的概述来读,也可以作为学习路 ...
随机推荐
- Nested Class(嵌套类)
在类.结构或接口中定义的类型称为嵌套类型. 例如 public class Container { class Nested { Nested() { } } } 不论外部类型是类.接口还是构造,嵌套 ...
- windows server 2012 r2 修改administrator密码
转至:https://jingyan.baidu.com/article/b907e627b615b646e7891cbf.html 1.进入开始面板,点击"管理工具". 2.双击 ...
- Python 爬取 "王者荣耀.英雄壁纸" 过程中的矛和盾
1. 前言 学习爬虫,最好的方式就是自己编写爬虫程序. 爬取目标网站上的数据,理论上讲是简单的,无非就是分析页面中的资源链接.然后下载.最后保存. 但是在实施过程却会遇到一些阻碍. 很多网站为了阻止爬 ...
- python 逻辑运算及奇怪的返回值(not,and,or)
首先,'and'.'or'和'not'的优先级是not>and>or. 同一优先级从左往右计算. 先说非运算,Python的非运算与这些语言相比,并没有特别的地方.not只有两个返回值,T ...
- Angular依赖注入:全面讲解(翻译中)
在实际使用Angular依赖注入系统时,你需要知道的一切都在本文中.我们将以实用易懂并附带示例的形式解释它的所有高级概念. Angular最强大.最独特的功能之一就是它内置的依赖注入系统. 大多数时候 ...
- php简易表单及下拉框动态渲染
<?php//1.连接数据库$link = mysqli_connect('127.0.0.1','root','root','1906');//2.设置字符集mysqli_set_charse ...
- think php 路由增删改查(搜索+关键字标红+缩略图)
路由 use think\Route; //展示添加表单 Route::get('create','user/user/create'); //表单提交数据 Route::post('save','u ...
- 物理机迁移至vmware
使用用vmware vcenter converter standalone将物理机迁移到虚拟机. 6.2版本下载地址如下: https://www.filehorse.com/download-vm ...
- os模块——关于在程序框中如何进行文件的查找和建立新的文件夹
- java笔记:00 数据类型