Home > DeveloperSection > Forums > Html with json mvc
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    October-29-2014 11:47 PM

 ASP.NET MVC HTML  JSON  Mvc4 
Ratings:


 1 Reply(s)
 619  View(s)
Rate this:

I need to pass html as parameter using json asp.net mvc2

I am trying to do like this:

$.ajax({

        type: "POST",

        dataType: "json",

        contentType: 'application/json; charset=utf-8',

        url: "/DefaultView/GeneratePDF",

        data: { "pdf": JSON.parse($("#displayContainer").html()) },

        success: function (data) {

            //nothing here

        }

    });

but it throws the "Uncaught SyntaxError: Unexpected token < " error.

using stringify() I am getting null here:

[HttpPost]

    [ValidateInput(false)]

    public virtual ActionResult GeneratePDF(string pdf)

    {

        pdf <---

    }



Pawan Shukla
Pawan Shukla

Total Post:29

Points:203
Posted on    October-29-2014 11:48 PM

Use the stringify method of JSON:

$.ajax({

        type: "POST",

        dataType: "json",

        contentType: 'application/json; charset=utf-8',

        url: "/DefaultView/GeneratePDF",

        data: { "pdf": JSON.stringify($("#displayContainer").html()) }, //change to stringify

        success: function (data) {

            //nothing here

        }

    });


Modified On Mar-17-2016 04:13:39 AM

Don't want to miss updates? Please click the below button!

Follow MindStick