ERROR: Unknown file table name - Uncaught Exception

ERROR: Unknown file table name - Uncaught Exception

marcasmar94marcasmar94 Posts: 6Questions: 2Answers: 0
edited May 11 in Free community support

I am getting this error "uncaught exception: Unknown file table name: Image " When i press on the record that has image uploaded

If i press on any other record that does not have uploaded images to it, i get no error

Uploading Images works fine

This is my code:

# Javascript:

    $(document).ready(function () {
            editor = new $.fn.dataTable.Editor({
                ajax: "api/products",
                table: "#example",
                fields: [
                 
                    {
                        label: "Name:",
                        name: "Product.Name"
                    },
                    {
                        label: "Description:",
                        name: "Product.Description"
                    }, {
                        label: "Price:",
                        name: "Product.Price",
                        attr: {
                            type: "number"
                        }
                    }, {
                        label: "Quantity:",
                        name: "Product.Quantity",
                        attr: {
                            type: "number"
                        }
                    },
                    {
                        label: "Color:",
                        name: "Product.ColorId",
                        type: "select"
                    }, {
                        label: "Size:",
                        name: "Product.SizeId",
                        type: "select"
                    }, {
                        label: "Material:",
                        name: "Product.MaterialId",
                        type: "select"
                    },
                    {
                        label: "In Stock:",
                        name: "Product.isInStock",
                        type: "select",
                        options: [
                            { label: "Yes", value: "true" },
                            { label: "No", value: "False" }
                        ]
                    }, {
                        label: "On Sale:",
                        name: "Product.isOnSale",
                        type: "select",
                        options: [
                            { label: "Yes", value: "true" },
                            { label: "No", value: "False" }
                        ]
                    },
                    {
                        label: "Images:",
                        name: "Image[].Id",
                        type: "uploadMany",
                        display: function (fileId, counter) {
                      ##    return '<img src="' + editor.file('**Image**', fileId).WebPath + '"/>';
                        },
                        noFileText: 'No images'
                    }
                ],
                formOptions: {
                    inline: {
                        onBlur: 'submit'
                    }
                }
            });

            // Activate an inline edit on click of a table cell
            $('#example').on('click', 'tbody td:not(:first-child)', function (e) {
                editor.inline(this);
            });

            var table = $('#example').DataTable({
                lengthChange: false,
                ajax: "api/products",
                columns: [

                    {
                        data: null,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false
                    },
                    { data: "Product.Name", className: 'editable' },
                    { data: "Product.Description", className: 'editable' },
                    { data: "Product.Price", className: 'editable', render: $.fn.dataTable.render.number(',', '.', 0, '', 'L.L') },
                    { data: "Product.Quantity", className: 'editable' },
                    { data: "Color.Name", className: 'editable', editField: "Product.ColorId" },
                    { data: "Size.Name", className: 'editable', editField: "Product.SizeId" },
                    { data: "Material.Name", className: 'editable', editField: "Product.MaterialId" },
                    { data: "Product.isInStock", className: 'editable' },
                    { data: "Product.isOnSale", className: 'editable' },
                    {
                        data: "Image[].Id",
                        render: function (d) {
                            return d.length ?
                                d.length + ' image(s)' :
                                'No image';
                        }
                    }
                ],
                select: true
            });

            // Display the buttons
            new $.fn.dataTable.Buttons(table, [
                { extend: "create", editor: editor },
                { extend: "edit", editor: editor },
                { extend: "remove", editor: editor },
                {
                    extend: 'collection',
                    text: 'Export',
                    buttons: [
                        'copy',
                        'excel',
                        'csv',
                        'pdf',
                        'print'
                    ]
                }
            ]);

            table.buttons().container()
                .appendTo($('div.eight.column:eq(0)', table.table().container()));
        });

# .Net Backend

  using (var db = new Database(dbType, dbConnection))
            {
                var response = new Editor(db, "Product", "Product.Id")
                 .Debug(true)
                 .Model<ProductViewModel>("Product")
                 .Model<Models.Color>("Color")
                 .Model<Models.Size>("Size")
                 .Model<Models.Material>("Material")
                 .Field(new Field("Product.ColorId")
                  .Options(new Options()
                   .Table("Color")
                   .Value("Id")
                   .Label("Name")
                  )
                 )
                 .LeftJoin("Color", "Color.Id", "=", "Product.ColorId")
                 .Field(new Field("Product.SizeId")
                  .Options(new Options()
                   .Table("Size")
                   .Value("Id")
                   .Label("Name")
                  )
                 )
                 .LeftJoin("Size", "Size.Id", "=", "Product.SizeId")
                 .Field(new Field("Product.MaterialId")
                  .Options(new Options()
                   .Table("Material")
                   .Value("Id")
                   .Label("Name")
                  )
                 )
                 .LeftJoin("Material", "Material.Id", "=", "Product.MaterialId")
                 .Field(new Field("Product.Name")
                  .Validator(Validation.NotEmpty(new ValidationOpts
                  {
                      Message = "Required"
                  }))
                 )
                 .MJoin(new MJoin("Image")
                  .Link("Product.Id", "ProductImage.ProductId")
                  .Link("Image.Id", "ProductImage.ImageId")

                  .Field(
                   new Field("Id")
                   .Upload(new Upload(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", "__ID____NAME____EXTN__"))
                    .Db("Image", "Id", new Dictionary<string, object> {
                             {
                              "WebPath",
                              Path.DirectorySeparatorChar + Path.Combine("uploads", "__ID____NAME____EXTN__")
                             },
                             {
                              "SystemPath",
                              Upload.DbType.SystemPath
                             },
                             {
                              "ImageName",
                              Upload.DbType.FileName
                             },
                             {
                              "ImageSize",
                              Upload.DbType.FileSize
                             },
                             
                    })
                    .Validator(Validation.FileSize(500000, "Max file size is 500K."))
                    .Validator(Validation.FileExtensions(new[] {
                         "jpg",
                         "png",
                         "gif"
                    }, "Please upload an image."))
                   )
                  )
                 )
                 .Field(new Field("Product.Description"))
                 .Field(new Field("Product.Price")
                  .Validator(Validation.Numeric())
                  .Validator(Validation.NotEmpty(new ValidationOpts
                  {
                      Message = "Only Numbers"
                  })))


                 .Field(new Field("Product.Quantity")
                  .Validator(Validation.Numeric())
                  .Validator(Validation.NotEmpty(new ValidationOpts
                  {
                      Message = "Only Numbers"
                  })))

                 .Field(new Field("Product.isOnSale")
                  .Validator(Validation.Boolean())
                  .SetFormatter(Format.IfEmpty(null))


                 ).Field(new Field("Product.isInStock")
                  .Validator(Validation.Boolean())
                  .SetFormatter(Format.IfEmpty(null))
                 )

                 .TryCatch(false)
                 .Process(Request)
                 .Data();
                return Json(response);
            }

This question has an accepted answers - jump to answer

Answers

  • marcasmar94marcasmar94 Posts: 6Questions: 2Answers: 0

    Do keep in mind that these table:

    • Image
    • Product
    • ProductImage

    Exist and in use so the Image table is there

  • allanallan Posts: 50,077Questions: 1Answers: 7,411 Site admin
    Answer ✓

    Hi,

    We exchanged e-mails about this on Saturday, but just in case anyone else searches for and finds this discussion, I've committed a fix for the issue here.

    Allan

  • marcasmar94marcasmar94 Posts: 6Questions: 2Answers: 0
    edited May 15

    Thank you Allan, The fix worked !

Sign In or Register to comment.