UTF-8 Charset problem at input | ASP.NET MVC

UTF-8 Charset problem at input | ASP.NET MVC

verityverity Posts: 2Questions: 1Answers: 0

Hi,

I'm currently testing out the datatables and editor libraries.
Working great and removing a lot of work from my project!

My problem is special character formatting for characters like ßäöüóúá and so on.
I run datatables-editor on ASP.NET MVC.
Importing data into MySQL from a CSV works flawless in UTF-8 (via MySQL LOAD DATA INFILE).
But entering strings via Editor in the Browser (Ajax/server side) results in HTML Number Code.

'ABCß' turns into 'ABC&#223'

The Ajax call is transfering ß as '&#223' and MySQL stores it then like that.

.
Datatables-Editor View

Ebene1 is from CSV import and correctly formatted
Ebene2 is manual input and is displayed correctly but wrong formatted.
Ebene3 is manual input where you can see, that the previous manual input is badly formatted and stored in MySQL.

MySQL Table

.

I can't find a way to manipulate that input, so that it is no HTML Number Code.
HTML and MySQL are configured for UTF-8_-unicode-ci _
I suppose that I would've to fix this somewhere in C# Code?
Would be amazing if someone could point me into a direction!

.
Thanks for reading and have a nice weekend :smiley:

.
.
.
Controller

public ActionResult Prod_edcOLD()
        {
            var dbType = Environment.GetEnvironmentVariable("DBTYPE");
            var dbConnection = Environment.GetEnvironmentVariable("DBCONNECTION");

            using (var db = new Database(dbType, dbConnection))
            {
                var response = new Editor(db, "prod_edc", "artikelnummer_edc")
                    .Model<Model_EDC>()
                    .Field(new Field("artikelnummer_edc"))
                    .Field(new Field("gtin_ean"))
                    .Field(new Field("lieferantenartikelnummer"))
                    .Field(new Field("ebene1"))
                    .Field(new Field("ebene2"))
                    .Field(new Field("ebene3"))
                    .Field(new Field("ebene4_basisklasse"))
                    .TryCatch(false)
                    .Process(Request)
                    .Data();

                return Json(response);
            }
        }

Model

public class Model_EDC
    {
        public string artikelnummer_edc { get; set; }
        public string gtin_ean { get; set; }
        public string lieferantenartikelnummer { get; set; }
        public string ebene1 { get; set; }
        public string ebene2 { get; set; }
        public string ebene3 { get; set; }
        public string ebene4_basisklasse { get; set; }
    }

Javascript

$(document).ready(function () {
            editor = new $.fn.dataTable.Editor({
                ajax: {
                    url: "/dataTables/prod_edcOLD"
                },
                table: "#example",
                type: "POST",
                fields: [
                {
                    label: "TEST:",
                    name: "",
                    type: "hidden"
                }, {
                    label: "artikelnummer_edc: ",
                    name: "artikelnummer_edc"
                }, {
                    label: "gtin_ean: ",
                    name: "gtin_ean"
                }, {
                    label: "lieferantenartikelnummer: ",
                    name: "lieferantenartikelnummer"
                }, {
                    label: "ebene1: ",
                    name: "ebene1"
                }, {
                    label: "ebene2: ",
                    name: "ebene2"
                }, {
                    label: "ebene3: ",
                    name: "ebene3"
                }, {
                    label: "ebene4_basisklasse: ",
                    name: "ebene4_basisklasse"
                }],
                formOptions: {
                    inline: {
                        onBlur: 'submit'
                    }
                }
            });

            $('#example').DataTable({
                dom: "Bfrtip",
                ajax: {
                    url: "/dataTables/prod_edcOLD",
                    type: "POST",
                    datatype: "json"

                },
                serverSide: true,
                processing: true,
                info: true,

                columns: [
                    {
                        data: null,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false,
                        searchable: false
                    },
                    { data: "artikelnummer_edc" },
                    { data: "gtin_ean" },
                    { data: "lieferantenartikelnummer" },
                    { data: "ebene1" },
                    { data: "ebene2" },
                    { data: "ebene3" },
                    { data: "ebene4_basisklasse" }
                ],
                order: [[1, 'asc']],

                keys: {
                    columns: ':not(:first-child)',
                    keys: [ 9 ],
                    editor: editor,
                    editOnFocus: true
                },
                select: {
                    style:    'os',
                    selector: 'td:first-child'
                },
                buttons: [
                    { extend: "create", editor: editor },
                    { extend: "edit", editor: editor },
                    { extend: "remove", editor: editor }
                ]
            });
        });

This question has an accepted answers - jump to answer

Answers

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

    Add .Xss(false) to the fields you don't what character encoded (in the C# code). The issue is the Microsoft AntiXSS library is really aggressive about encoding HTML entities!

    Allan

  • verityverity Posts: 2Questions: 1Answers: 0

    Many thanks for the quick answer! :wink:

This discussion has been closed.