Implementing a checkbox in Editor using http://editor.datatables.net/examples/api/checkbox.html

Implementing a checkbox in Editor using http://editor.datatables.net/examples/api/checkbox.html

KasamaliHasanKasamaliHasan Posts: 11Questions: 1Answers: 0

Hi I am trying to implement a checkbox field in Editor for my database field of type bit in SQL Server.

I am reffering to the local version of the above example for .NET i.e http://localhost:xxx/Web/examples/api/checkbox.html

When I run this example I get the following error in the Firefox debugger:

Message: "No HTTP resource was found that matches the request URI 'http://localhost:xxxxx/api/checkbox?_=1443533414355'."
MessageDetail: "No type was found that matches the controller named 'checkbox'."

I can see that the following request is made from the browser:
http://localhost:xxxxx/api/checkbox?_=1443533414355

and I think there is no Checkbox controller present in the Controllers folder of the downloaded examples

I suppose the corresponding examples at http://editor.datatables.net/examples/api/checkbox.html is working as it is using PHP

Do you have missing controller?

Regards
Hasan
KasamaliHasan@Yahoo.co.uk

Replies

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

    Hi Hasan,

    Thanks for letting me know about this - the controller and model are missing from the 1.5.1 download package for .NET. They should be:

    Model:

    namespace WebApiExamples.Models
    {
        public class CheckboxModel
        {
            public string first_name { get; set; }
    
            public string last_name { get; set; }
    
            public string phone { get; set; }
    
            public string city { get; set; }
    
            public string zip { get; set; }
    
            public int active { get; set; }
        }
    }
    

    Controller:

    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.IO;
    using DataTables;
    using WebApiExamples.Models;
    using System.Net.Http.Formatting;
    using System.Web;
    using System.Web.Http;
    
    namespace WebApiExamples.Controllers
    {
        public class CheckboxController : ApiController
        {
            [HttpGet, HttpPost, Route("api/checkbox")]
            public IHttpActionResult Checkbox()
            {
                var request = HttpContext.Current.Request;
                var settings = Properties.Settings.Default;
    
                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    var response = new Editor(db, "users")
                        .Model<CheckboxModel>()
                        .Field(new Field("image")
                            .SetFormatter((val, data) => val == "" ? 0 : 1)
                        )
                        .Process(request)
                        .Data();
    
                    return Json(response);
                }
            }
        }
    }
    

    I'll have them in 1.5.2!

    Regards,
    Allan

This discussion has been closed.