0

I'm working with inline SVG. I need to send the SVG content to a server (running ASP.NET MVC) with other informations from the page. The code below works fine when the SVG content is small, but when the content is too big, the data is not being sent, it's not even sent to the Controller.

Javascript:

function saveSVG() {
        var rack = document.getElementsByClassName("cwRacksSvgImg");
        var markupTOs = '';
        var script = associados.slice();

        for (var i = 0; i < rack.length; i++) {
            markupTOs = markupTOs + (new XMLSerializer()).serializeToString(rack[i]);
        }

        var svg = document.getElementsByTagName('svg')[0];
        var floor_id = document.getElementById('floor_id').value;
        var markup = (new XMLSerializer()).serializeToString(svg);
        $.ajax({
            type: 'Post',
            dataType: 'json',
            url: '/Planta/SavePlanta/',
            data: JSON.stringify({
                markup: markup,
                markupTOs: markupTOs,
                floor_id: floor_id,
                script: script
            }),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
            }
        });
    }

Controller

public ActionResult SavePlanta(string markup, string markupTOs, int floor_id, string[] script) {

var bytes = Encoding.UTF8.GetBytes(markup);

}

Any suggestions to a similar approach that can deal with large SVG data?

Thank you in advance for your help!

Sah
  • 189
  • 1
  • 2
  • 11
  • Instead of converting it to a json client side, you could try `encodeURIComponent()`, and then json encode it on the server. It may also break in some extent (>207588000 chars in FF). – Kaiido Jan 07 '16 at 06:13
  • Thanks for your reply, I solved the problem using this solution: http://forums.asp.net/t/1751116.aspx?How%20to%20increase%20maxJsonLength%20for%20JSON%20POST%20in%20MVC3 – Sah Jan 07 '16 at 15:11

1 Answers1

0

The problem was that due the big amount of data, I was receiving the error:

Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

I solved the problem following this post:

http://forums.asp.net/t/1751116.aspx?How%20to%20increase%20maxJsonLength%20for%20JSON%20POST%20in%20MVC3

Sah
  • 189
  • 1
  • 2
  • 11