Save datatable editor varchar as UTF8 - .Net

Save datatable editor varchar as UTF8 - .Net

creadoscreados Posts: 2Questions: 0Answers: 0
edited March 2019 in Editor

Hi everyone!

I have a problem with datatable editor. I need to save a varchar field as utf8 with spanish accents, but it is saving ascii code instead.

I need to save 'á'.

Datatable editor .Net:

        public static DtResponse Centros(HttpRequestBase Request, MySqlConnection Conexion)
        {
            DtResponse respuesta = null;

            using (var db = new Database("mysql", Conexion.ConnectionString))
            {
                respuesta = new Editor(db, "centros", "IdCentro")
                                .Model<Centro>("centros")
                                .Model<TipoCentro>("tipocentro")
                                .Model<Provincias>("provincias")
                                .Field(new Field("centros.Tipo")
                                    .Options("tipocentro", "idTipoCentro", "Nombre")
                                    .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                                )
                                .Field(new Field("centros.IdProvincia")
                                    .Options(new Options()
                                                .Table("provincias")
                                                .Value("idProvincia")
                                                .Label("nombre")
                                                .Where(q => q.Where("andalucia", 1))
                                            )
                                    .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                                )
                                .LeftJoin("tipocentro", "tipocentro.idTipoCentro", "=", "centros.Tipo")
                                .LeftJoin("provincias", "provincias.idProvincia", "=", "centros.IdProvincia")
                                .Process(Request.Params)
                                .Data();
            }

            return respuesta;
        }

MySql Table definition:

CREATE TABLE `centros` (
    `IdCentro` INT(10) NOT NULL AUTO_INCREMENT,
    `nombre` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_spanish_ci',
    `tipo` INT(11) NOT NULL,
    `IdProvincia` SMALLINT(6) NOT NULL,
    PRIMARY KEY (`IdCentro`),
    INDEX `FK_centros_tipocentro` (`tipo`),
    INDEX `FK_centros_provincias` (`IdProvincia`),
    CONSTRAINT `FK_centros_provincias` FOREIGN KEY (`IdProvincia`) REFERENCES `provincias` (`idProvincia`),
    CONSTRAINT `FK_centros_tipocentro` FOREIGN KEY (`tipo`) REFERENCES `tipocentro` (`IdTipoCentro`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=13
;

Replies

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Add .Xss(false) to your Field definition. Its the Microsoft XSS filter that is causing that.

    Allan

  • creadoscreados Posts: 2Questions: 0Answers: 0

    Thanks Allan!

This discussion has been closed.