BootstrapBlazor component use: data annotation

foreword

BootstrapBlazor (referred to as BB for short) is a particularly useful component that basically satisfies most of the functions. There is no problem with the business logic, and the official documentation is also very detailed. (You will understand what a good document is after reading the document that only gives cases)

BB Official Documentation

BB data annotation

BB is actually a component for back-end management development, especially suitable for enterprise-level development. It can be said to be a specialized version of the component for small projects.

Recommended development techniques

  • Blazor Server (SSR): server-side rendering, front-end and back-end development are not separated.
  • BoostrapBlazor: UI component library
  • SqlSugar: database

The development speed is called a fast one. There is no need to consider cross-domain, and you are not afraid of security information leakage (because it is SSR, the browser can only get the rendering result), the front-end directly gets the data from the back-end.

The only problem is that high concurrency is not supported. It is safe to have less than 1,200 people. If it is more than 1,200 people with high concurrency, then you have to use microservices. This is Internet development (microservices, distributed, memory cache). Most businesses cannot achieve this level. So it is especially suitable for small projects

Data annotation source code

BootstrapBlazor/ src / BootstrapBlazor.Shared / Data / Foo.cs

Introduction to Data Annotation

  • Display
    • Name: name
  • AutoGenerateColumn
    • Ignore whether to ignore
    • order sorting
    • FormatString: format
  • Required
    • ErrorMessage: inspection error error message

Annotate a simple example

Many data related to BB are related to this annotation. It mainly depends on whether there is a data variable of Model.

insert image description here

insert image description here

BB edit popup

ValidateForm form component

Introduction

Add BB annotations to the objects generated by sqlsugar

public partial class T_Joint
{
    
    

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:False
    /// </summary>           
    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
    [AutoGenerateColumn(Ignore =true)]
    public long Id {
    
     get; set; }

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>   
    [Display(Name = "创建时间")]

    public DateTime? CreateTime {
    
     get; set; } = DateTime.Now;

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [Display(Name = "修改时间")]

    public DateTime? Time {
    
     get; set; }= DateTime.Now;

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [AutoGenerateColumn(Ignore = true)]
    public bool IsDel {
    
     get; set; } = false;

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [AutoGenerateColumn(Ignore = true)]
    public bool IsClick {
    
     get; set; } = false;

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [AutoGenerateColumn(Ignore = true)]
    public int? ParentId {
    
     get; set; }

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [AutoGenerateColumn(Ignore = true)]
    public string Path {
    
     get; set; }

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [AutoGenerateColumn(Ignore = true)]
    public int? Deep {
    
     get; set; }




    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [Display(Name = "排序号")]
    public int? OrderNum {
    
     get; set; } = 0;



    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>      
    [Display(Name = "名称")]
    
    [Required(ErrorMessage ="{0}不能为空")]
    public string Name {
    
     get; set; }

    /// <summary>
    /// Desc:
    /// Default:
    /// Nullable:True
    /// </summary>           
    [AutoGenerateColumn(Ignore = true)]
    public long? UserId {
    
     get; set; }

}

use

//注入对话框服务
[Inject]
private DialogService DialogService {
    
     get; set; }
......

//随便一个按钮绑定一个事件

public async Task AddRootBtn()
{
    
    
    var option = new EditDialogOption<T_Joint>()
    {
    
    
        Title = "节点编辑",
        Model = new T_Joint() {
    
     },
        RowType = RowType.Inline,
        ItemsPerRow = 2,
        ItemChangedType = ItemChangedType.Update,
        Items = Items,
        
    };

    await DialogService.ShowEditDialog(option);
}


Effect

insert image description here

Guess you like

Origin blog.csdn.net/qq_44695769/article/details/132424523