【问题标题】:Use UIOMaticField or backoffice controls in Ui-O-Matic Umbraco在 Ui-O-Matic Umbraco 中使用 UIOmaticField 或后台控件
【发布时间】:2017-04-12 13:38:41
【问题描述】:

我是 Umbraco CMS 的新手。我在我的项目中使用 Ui-O-Matic 插件。
Ui-O-Matic 允许对数据库进行简单的 CRUD 操作。但我想使用文件、文本区域等后台控件。

所以我在 database.cs 文件中像这样使用 UIOmaticField。

 [Column("newsDetail")]
 [UIOMaticField("News Detail","Add Details",View ="textarea")]
 public string newsDetail { get; set; }

 [Column("newsImage")]
 [UIOMaticField("Image","Upload Image",View ="file")]
 public string newsImage { get; set; }

问题是当我对数据库进行任何更改时,我必须刷新 database.tt 文件以获取数据库更改。但它会重新创建 database.cs 文件和我之前的更改:

[UIOMaticField("News Detail","Add Details",View ="textarea")]

从 database.cs 文件中删除。每次我都必须做同样的改变。
请指导我应该怎么做才能保持我的自定义更改原样即使我刷新了 database.tt 文件?
其他更好的方式来做 CRUD 操作也是可取的。

【问题讨论】:

    标签: asp.net-mvc umbraco umbraco7 umbraco6 umbraco-contour


    【解决方案1】:

    在谷歌上搜索了很多之后,我发现由于 database.cs 文件是自动生成的,我不能在其中进行自定义更改。
    我找到了另一种使用后台控制的方法。让我在这里解释一下,可能会对其他人有所帮助。

    不要在 databse.cs 文件中编写 UIOMatoicField,而是创建模型来执行相同的操作。
    在“Models/Generated/database.tt”文件中进行以下更改

    // Settings 
        ConnectionStringName = "umbracoDbDSN";          // Uses last connection string in config if not specified
        Namespace = "Generator";
        RepoName = "";
        GeneratePocos = true;
        ClassPrefix = "";  
        ClassSuffix = "";  
    
        // Read schema 
        var tables = LoadTables();  
        tables["Course"].Ignore = true; // Prevents table to include in databse.cs file  
        tables["News"].Ignore = true; 
    if (tables.Count>0)
        {
    #>
    <#@ include file="UIOMatic.Generator.ttinclude" #>
    <# } #>
    

    然后如下创建新模型。例如。 “模型\NewsModel.cs”

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using UIOMatic.Attributes;
    using UIOMatic.Enums;
    using UIOMatic.Interfaces;
    using Umbraco.Core.Persistence;
    using Umbraco.Core.Persistence.DatabaseAnnotations;
    
    namespace EdumentUIOMatic.Models
    {
        [Umbraco.Core.Persistence.TableName("News")]
        [PrimaryKey("newsId")]
        [UIOMatic("News", "icon-box-open", "icon-box-open", RenderType = UIOMaticRenderType.List, ConnectionStringName = "umbracoDbDSN")]   
        public class NewsModel: IUIOMaticModel
        {
            [UIOMaticIgnoreField]
            [Column("newsId")]
            public int newsId { get; set; }
    
            [Column("newsTitle")]
            [UIOMaticField("News Title", "Add Title")]
            public string newsTitle { get; set; }
    
            [Column("newsDetail")]
            [UIOMaticField("News Detail", "Add Details", View = "textarea")]
            public string newsDetail { get; set; }
    
            [Column("newsImage")]
            [UIOMaticField("Image", "Upload Image", View = "file")]
            public string newsImage { get; set; }
    
    
    
            [Column("isDeleted")]
            [UIOMaticField("Hide News", "Check if you want to hide this news")]        
            public bool isDeleted { get; set; }
    
    
    
            [System.Web.Http.AcceptVerbs("GET", "POST")]
            public IEnumerable<Exception> Validate()
            {
                return new List<Exception>();
            }
        }
    }
    

    现在,如果您重新加载 database.tt 文件以获取更新的数据库,您的代码将不会被删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多