Problem with Data shown in table only

Problem with Data shown in table only

info@invisiblefarm.itinfo@invisiblefarm.it Posts: 11Questions: 4Answers: 0

Error messages shown: Unable to cast value to be String
Description of problem:
Hi, I'm usign Datatables Editor .NET Framework
I need to reproduce this example but I've got always "Unable to cast value to be String"
I don't use a fixed Model but create field on fly; this is my controller class

private ActionResult DoAction(string table, System.Web.HttpRequest request, string action = null)
{
    bool action_defined = !string.IsNullOrWhiteSpace(action);
    GestioneDizionarioModel page_model = new GestioneDizionarioModel(table);
    DtResponse response = null;

    using (Database db = DbExtensions.GetDatabaseConnection())
    {
        Editor editor = new Editor(db, table, "chiave");
        if (!string.IsNullOrWhiteSpace(action))
        {
            editor.Field(
                new Field("last_update", typeof(DateTime), null)
                .Set(Field.SetType.Both)
                .DbType(System.Data.DbType.DateTime)
                .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_822))
                .SetFormatter(Format.DateFormatToSql("yyyy-MM-dd HH:mm:ss"))
            );
        }
        foreach (FieldInformation field in page_model.dizionarioModel.fields)
        {
            editor.Field(new Field(field.name));
        }

        if (action_defined && action.Equals("remove"))
        {
            // Disallow delete just in case anyone uses the API to do it
            editor.PreRemove += (sender, args) => args.Cancel = true;
        }

        editor.Process(request);
        response = editor.Data();
    }

    if (action_defined)
    {
        DizionariCondivisiLogger.LogUpdateStatisticheDizionario(table, DbExtensions.GetTableRowsCount(table));
    }

    return Json(response);// new { response = response });
}

How can resolve? Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,443Questions: 1Answers: 10,053 Site admin

    You'll need to use a string type for the DateTime I'm afraid. The problem with using DateTime is that it can't be directly represented in JSON, which we use as the transport format.

    Regards,
    Allan

  • allanallan Posts: 61,443Questions: 1Answers: 10,053 Site admin
    Answer ✓

    I should note that you can still use DateTime in the db!!! Only in C#-land does it need to be a string.

  • info@invisiblefarm.itinfo@invisiblefarm.it Posts: 11Questions: 4Answers: 0

    I read a lot of time .NET Editor example "Table only data" and I found only now that there is a trigger on table users

    I'm going to implement this solution,
    thanks

This discussion has been closed.