Uncaught Unknown file table name: Item.Item_Image

Uncaught Unknown file table name: Item.Item_Image

bank1991bank1991 Posts: 8Questions: 3Answers: 0

C# CONTROLLER **
Hello, guys am trying to use the upload feature but I keep getting this error **Uncaught Unknown file table name: Item.Item_Image
what am doing wrong?

public ActionResult Item_Get_Vendor()
{
try
{
var request = System.Web.HttpContext.Current.Request;

                        var formData = HttpContext.Request.Form;
                        var settings = Properties.Settings.Default;

                        using (var db = new Database(settings.DbType, settings.DbConnection))
                        {
                            //TO DO: See if User_ID session variable is set.
                            int user_id = 4;
                            var response = new Editor(db, "Item", "ID")
                                .Model<Item>("Item")
                                .**Field(new Field("Item.Item_Image")
                                 .Upload(new Upload(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", "__ID____NAME____EXTN__"))
                                  .Db("Item", "Item.Item_Image", new Dictionary<string, object>
                                  {

                                  })
                                  .Validator(Validation.FileSize(500000, "Max file size is 500K."))
                                  .Validator(Validation.FileExtensions(new[] {
                                       "jpg",
                                       "png",
                                       "gif"
                                  }, "Please upload an image."))
                                 )
                                )**
                                .Model<Item_Group>("Item_Group")
                                .LeftJoin("dbo.Item_Group", "Item_Group.ID", "=", "Item.Item_Group_ID")
                                .Field(new Field("Item.Item_Group_ID")
                                    .Options("dbo.Item_Group", "ID", "Description")
                                    .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                                )               
                                .TryCatch(false)
                                .Process(formData)
                                .Data();

                            return Json(response, JsonRequestBehavior.AllowGet);
                        }
                    }
                    catch (Exception Ex)
                    {
                        return Json(new { error = Ex.Message.ToString() }, JsonRequestBehavior.AllowGet);
                    }
                }

DataTable Code

      var Datatable_Items = $('#Items').DataTable({
                dom: "Bfrtip",
                ajax: "/Item/Item_Get_Vendor",
                    order: [[1, 'asc']],
                    columns: [
                        {
                            data: null,
                            defaultContent: '',
                            className: 'select-checkbox',
                            orderable: false
                        },
                    { "data": "Item_Group.Description", visible: true },
                    { "data": "Item.Item_Name", "autowidth": true, visible: true },
                    { "data": "Item.Description", "autowidth": true, visible: true },
                    **{
                        "data": "Item.Item_Image", "autowidth": true, visible: true,
                        render: function (file_id) {
                            return file_id ?
                                '<img src="' + Editor_Items.file('Item', file_id).web_path + '"/>' :
                                null;
                        },
                        defaultContent: "No image",
                        title: "Image"
                    },**
                    { "data": "Item.Taxable", render: function (val, type, row) {
                                return val == 0 ? "No" : "Yes";
                    }
                    },
                        {
                            "data": "Item.Service_Item", render: function (val, type, row) {
                                return val == 0 ? "No" : "Yes";
                        }
                    },
                    { "data": "Item.Vendor_Description", "autowidth": true, visible: true },
                    { "data": "Item.Vendor_Item_Image", "autowidth": true, visible: true },
                    { "data": "Item.Vendor_Taxable", "autowidth": true, visible: true },
                    { "data": "Item.Vendor_Service_Item", "autowidth": true, visible: true },
                    {
                        "data": "Item.Active", "render": function (val, type, row) {
                            return val == 0 ? "No" : "Yes";
                        }
                    },
                    { "data": "Item.Sourcing_Approved_Create", "autowidth": true, visible: true },
                    { "data": "Item.Sourcing_Approved_Modify", "autowidth": true, visible: true },
                ],
                scrollY: ($(window).height() - 290),
                scrollX: true,
                scrollCollapse: true,
                select: true,
                buttons: [
                    { extend: "create", editor: Editor_Items },
                    { extend: "edit", editor: Editor_Items },
                    { extend: "remove", editor: Editor_Items },
                    {
                        extend: 'collection',
                        text: 'Export',
                        buttons: [
                            'excel',
                            'csv',
                            'pdf',
                            'print'
                        ]
                    }
                ]
            });

Answers

  • bank1991bank1991 Posts: 8Questions: 3Answers: 0

    Sorry, this is the error am getting instead DataTables warning: table id=Items - An item with the same key has already been added.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    Can you show me the code for your two models please? Also, is that error only happening when Field(new Field("Item.Item_Image") is defined in the above code, or something else?

    Thanks,
    Allan

  • bank1991bank1991 Posts: 8Questions: 3Answers: 0

    It's just one model (Item) that has the field Item_Image. Below is the code for the model.

    namespace iSource_Editor.Models
    {
        [Table("Item")]
        public class Item
        {
            public int ID { get; set; }        
    
            public int? Item_Group_ID { get; set; }
    
            public string Item_Name { get; set; }
    
            public string Code { get; set; }
    
            public string Description { get; set; }
            public string Item_Image { get; set; }
    
            public string Taxable { get; set; }
    
            public string Service_Item { get; set; }        
    
            public int? Vendor_Item_Group_ID { get; set; }
    
            //public string Vendor_Item_Group { get; set; }
    
            public string Vendor_Code { get; set; }
    
            public string Vendor_Description { get; set; }
    
            public string Vendor_Taxable { get; set; }
    
            public string Vendor_Service_Item { get; set; }
            public string Vendor_Item_Image { get; set; }
    
            public string Active { get; set; }
            public string Sourcing_Approved_Create { get; set; }
            public string Sourcing_Approved_Modify { get; set; }
        }
    }
    

    No, I think it has to do with this line

    .Db("Item", "Item.Item_Image", new Dictionary<string, object>
                      {
    
                      })
    

    it seems me calling the item model twice is causing the error but I can't also seem to know how to take one out and get both sides working.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Many thanks for that - I'm afraid I'm going to need to ask for some more information though... Sorry! Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    The error message you have above would occur if you were calling editor.file('Item.Item_Image') - but I don't see that anywhere in your code above, so I'm not certain what is triggering the error.

    Thanks,
    Allan

This discussion has been closed.