anurag anurag - 20 days ago 5
Ajax Question

Sending Data from jQuery Ajax to MVC COntroller

I am trying to send an SVG string from my index page to my controller. But it's getting a null value.

var str = "<svg height=\"350\" version=\"1.1\" ... svg properties ..."

type: "POST",
//contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
//dataType: "text",
url: window.location.origin + '/NavigationExport/GetSvgData',
//data: '{"value":"' + str + '"}',
data: {value :str},
}).done(function (data) {

Here is my controller code.

public void GetSvgData(string value)

but this code is giving me a 500 internal server error.

A potentially dangerous Request.Form value was detected from the client (
value="<svg height="350" ve..."

Description: ASP.NET has detected data in the request that is
potentially dangerous because it might include HTML markup or script.
The data might represent an attempt to compromise the security of your
application, such as a cross-site scripting attack. If this type of
input is appropriate in your application, you can include code in a
web page to explicitly allow it. For more information, see

If I use

data: '{"value":"' + str + '"}'

it sends null value to the controller


The issue is because MVC thinks you're trying to send HTML in the request, and prevents it to stop any XSS attacks. You can allow HTML/XML by adding the ValidateInput annotation to Action. In your case, try this:

public void GetSvgData(string value)