Editor dll not populating table

Editor dll not populating table

dpanscikdpanscik Posts: 119Questions: 32Answers: 0

Alrighty... Still struggling to make the editor dll work within an existing project.

Still need some help here to get editor dll working.

At the moment I am trying to use the controller furnished by "editor generator". This first test is to get data to load into the table (not even trying to edit or insert just yet).

On the first run of the controller the table is made in the database.

Here is the controller. Its pretty much the stock controller from "editor generator"

    public class OnCallDataController : ApiController
    {
        [System.Web.Http.Route("api/OCD")]
        [System.Web.Http.HttpGet]
        [System.Web.Http.HttpPost]
        public IHttpActionResult DataTransport()
        {
            var settings = Properties.Settings.Default;
            var request = HttpContext.Current.Request;


            using (var db = new Database(settings.DbType, settings.DbConnection))
            {
                db.Sql(@"IF object_id('Flex_OnCall_3', 'U') is null
                            CREATE TABLE Flex_OnCall_3 (
                                [TableID] int not null identity,
                                [day] date,
                                [shop] nvarchar(255),
                                [name] nvarchar(255),
                                [phone] nvarchar(255),
                                [email] nvarchar(255),
                                PRIMARY KEY( [TableID] )
                );");

                    var response = new Editor(db, "Flex_OnCall_3", "TableID")
                        .Model<Flex_OnCall_3Model>()
                        .Field(new Field("day")
                                .Validator(Validation.DateFormat(Format.DATE_ISO_2822))
                                .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_2822))
                                .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_2822))
                        )
                         .Process(request)
                        .Data();

                return Json(response);
            }
        }
    }

then I have a break in Visual Studio just before the json gets returned.

here is what is getting ready to be returned

here is the browser error message

here is the output from Network

{"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Method not found: 'System.String[] System.String.Split(Char, System.StringSplitOptions)'.","fieldErrors":[],"id":null,"meta":{},"options":{},"searchBuilder":{"options":{}},"searchPanes":{"options":{}},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}

Now if I use a controller for another table, on this table. It loads just fine. But of course it doesn't have editor functions.
This controller works!

        public ActionResult LoadData()
        {
            

            using (LincolnUserDataEntities _context = new LincolnUserDataEntities())
            {
                var draw = Request.Form.GetValues("draw").FirstOrDefault();
                var start = Request.Form.GetValues("start").FirstOrDefault();
                var length = Request.Form.GetValues("length").FirstOrDefault();
                string sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
                string sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
                var searchValue = Request.Form.GetValues("search[value]").FirstOrDefault();
                string form_id = Request.Form.GetValues("form_id").FirstOrDefault();

                //Paging Size (10,20,50,100)    
                int pageSize = length != null ? Convert.ToInt32(length) : 0;
                int skip = start != null ? Convert.ToInt32(start) : 0;
                int recordsTotal = 0;

                // Getting all On Call Data
                var OnCallDB = _context.Flex_OnCall_3.Where(x => x.day != DateTime.Now);

                //Sorting    
                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                {
                    //shippingData = shippingData.OrderBy(g => sortColumn + " " + sortColumnDir);
                    switch (sortColumn)
                    {   case "JobNumber":
                            OnCallDB = sortColumnDir.ToLower() == "asc" ? OnCallDB.OrderBy(x => x.day) : OnCallDB.OrderByDescending(x => x.day);
                            break;
                        default:
                            OnCallDB = OnCallDB.OrderBy(x => x.day);
                            break;
                    }
                }
                //Search    
                if (!string.IsNullOrEmpty(searchValue))
                {
                    OnCallDB = OnCallDB.Where(m => m.name.Contains(searchValue) || m.shop.Contains(searchValue));
                }
                //total number of rows count     
                recordsTotal = OnCallDB.Count();
                //Paging     
                var data = OnCallDB.Skip(skip).Take(pageSize).ToList();
                //Returning Json Data    
                return Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data });
            }
        }

here is the result in the browser

Answers

  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0

    I forgot to include the model. Here it is. Pretty much also stock from Editor Generator.

    /*
     * Model for DB table Flex_OnCall_3
     * Created by http://editor.datatables.net/generator
     */
    using System;
    
    namespace AppOwnsData.Models
    {
      
        
        public class Flex_OnCall_3Model
        {
            public string day { get; set; }
    
            public string shop { get; set; }
    
            public string name { get; set; }
    
            public string phone { get; set; }
    
            public string email { get; set; }
        }
    }
    
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    This is for .NET Framework 4.8? Have you used the DataTables.dll from lib/net48 in Generator, or somewhere else? Have you tried removing that local reference and instead using the Nuget package?

    Allan

  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0
    edited March 2023

    I downloaded a fresh editor package at (https://editor.datatables.net/download/) and got the (4.8) dll file copied to replace the old dll.

    Still getting an error, but now the error is different.

    Here is the break in Visual Studio showing the pending json response.

    here is the result in Network

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Unknown field: Shop (index 2)","fieldErrors":[],"id":null,"meta":{},"options":{},"searchBuilder":{"options":{}},"searchPanes":{"options":{}},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}
    

    here is the controller

        public class OnCallDataController : ApiController
        {
            [System.Web.Http.Route("api/OCD")]
            [System.Web.Http.HttpGet]
            [System.Web.Http.HttpPost]
            public IHttpActionResult DataTransport()
            {
                var settings = Properties.Settings.Default;
                var request = HttpContext.Current.Request;
    
    
                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    db.Sql(@"IF object_id('Flex_OnCall_3', 'U') is null
                                CREATE TABLE Flex_OnCall_3 (
                                    [TableID] int not null identity,
                                    [day] date,
                                    [shop] nvarchar(255),
                                    [name] nvarchar(255),
                                    [phone] nvarchar(255),
                                    [email] nvarchar(255),
                                    PRIMARY KEY( [TableID] )
                    );");
    
                    var response = new Editor(db, "Flex_OnCall_3Model", "TableID")
                        .Model<Flex_OnCall_3Model>()
                        .Field(new Field("day")
                                .Validator(Validation.DateFormat(Format.DATE_ISO_2822))
                                .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_2822))
                                .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_2822))
                        )
                         .Process(request)
                        .Data();
    
                    return Json(response);
                }
            }
    

    here is the model

    /*
     * Model for DB table Flex_OnCall_3
     * Created by http://editor.datatables.net/generator
     */
    using System;
    
    namespace AppOwnsData.Models
    {
      
        
        public class Flex_OnCall_3Model
        {
            public string day { get; set; }
    
            public string shop { get; set; }
    
            public string name { get; set; }
    
            public string phone { get; set; }
    
            public string email { get; set; }
        }
    }
    

    here is a screenshot of the database

  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0

    Today I downloaded a fresh editor package (https://editor.datatables.net/download/)

    I got the 4.8 dll out of the package and replaced the dll that is in the project/solution.

    Now I am getting a different error.

    Here is the screenshot of json getting ready to be returned.

    Here is the result in Network

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Unknown field: Shop (index 2)","fieldErrors":[],"id":null,"meta":{},"options":{},"searchBuilder":{"options":{}},"searchPanes":{"options":{}},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}
    

    here is the controller

        public class OnCallDataController : ApiController
        {
            [System.Web.Http.Route("api/OCD")]
            [System.Web.Http.HttpGet]
            [System.Web.Http.HttpPost]
            public IHttpActionResult DataTransport()
            {
                var settings = Properties.Settings.Default;
                var request = HttpContext.Current.Request;
    
    
                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    db.Sql(@"IF object_id('Flex_OnCall_3', 'U') is null
                                CREATE TABLE Flex_OnCall_3 (
                                    [TableID] int not null identity,
                                    [day] date,
                                    [shop] nvarchar(255),
                                    [name] nvarchar(255),
                                    [phone] nvarchar(255),
                                    [email] nvarchar(255),
                                    PRIMARY KEY( [TableID] )
                    );");
    
                    var response = new Editor(db, "Flex_OnCall_3Model", "TableID")
                        .Model<Flex_OnCall_3Model>()
                        .Field(new Field("day")
                                .Validator(Validation.DateFormat(Format.DATE_ISO_2822))
                                .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_2822))
                                .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_2822))
                        )
                         .Process(request)
                        .Data();
    
                    return Json(response);
                }
            }
    

    here is the model

    /*
     * Model for DB table Flex_OnCall_3
     * Created by http://editor.datatables.net/generator
     */
    using System;
    
    namespace AppOwnsData.Models
    {
      
        
        public class Flex_OnCall_3Model
        {
            public string day { get; set; }
    
            public string shop { get; set; }
    
            public string name { get; set; }
    
            public string phone { get; set; }
    
            public string email { get; set; }
        }
    }
    

    here is the screenshot of the database

  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0

    If I do the following;
    change "shop" in database to "Shop"
    change "shop" in model to "Shop"

    the error message changes to;

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Method not found: 'System.String[] System.String.Split(Char, System.StringSplitOptions)'.","fieldErrors":[],"id":null,"meta":{},"options":{},"searchBuilder":{"options":{}},"searchPanes":{"options":{}},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}
    
  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0

    I forgot datatable 101. In your view data, model, and database fields all need to match.

    In the view I had;
    { "data": "Shop", "title": "Shop", "name": "Shop", "autoWidth": true }

    I changed the view to
    { "data": "shop", "title": "Shop", "name": "Shop", "autoWidth": true }

    then changed model from "Shop" back to "shop"

    then changed the database from "Shop" back to "shop"

    now I am back to getting this error message in network

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Method not found: 'System.String[] System.String.Split(Char, System.StringSplitOptions)'.","fieldErrors":[],"id":null,"meta":{},"options":{},"searchBuilder":{"options":{}},"searchPanes":{"options":{}},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}
    
  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0

    ok... so Ive made one small progress. Updating the referenced dll.

    In visual studio if you remove a reference. Then add a new reference (with a new path) to the new DLL. The old DLL will still be referenced. Visual Studio REFUSES to update the path. Once you establish the path in Visual Studio you cannot change it.

    To update the DLL you MUST overwrite the old DLL with the new DLL.

    Now that I have done that.... Here is my error message in Network.

    I get; "Invalid object name 'Flex_OnCall_3Model'."

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Invalid object name 'Flex_OnCall_3Model'.","fieldErrors":[],"id":null,"meta":{},"options":{},"searchBuilder":{"options":{}},"searchPanes":{"options":{}},"files":{},"upload":{"id":null},"debug":null,"cancelled":[]}
    

    and again here is my Model

    /*
     * Model for DB table Flex_OnCall_3
     * Created by http://editor.datatables.net/generator
     */
    using System;
    
    namespace AppOwnsData.Models
    {
      
        
        public class Flex_OnCall_3Model
        {
            public string day { get; set; }
    
            public string shop { get; set; }
    
            public string name { get; set; }
    
            public string phone { get; set; }
    
            public string email { get; set; }
        }
    }
    
  • dpanscikdpanscik Posts: 119Questions: 32Answers: 0

    Solved.

    The model Name in the controller, the model name in the model, and the table name in the database all need to match.

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Nice monologue :)

    To update the DLL you MUST overwrite the old DLL with the new DLL.

    :( That I did not know. How annoying.

    Super to hear that you've got this working now - thanks for toughing it out and letting me know the steps you followed.

    Allan

Sign In or Register to comment.