JQuery - $.ajax POST does not send data with “<” symbol to controller RRS feed

  • Question

  • User-1634604574 posted

    JQuery - $.ajax POST does not send data with “<” symbol to controller

                        type: "post",
             cache: false,
                        url: "/Print_Format/GetJavascriptFile",
              //contentType: "application/json; charset=utf-8",
                //                    dataType: "json"
                   data: {f:"<pp>"},
             success: function (data) {
            public ActionResult GetJavascriptFile( string f)
              //  f = "jquery-1.10.2.min.js";
                string mp = @"C:\temp\"+f+"";
               // return File(mp, "text/javascript");
                return Json( mp, "text/javascript");

    why i cannot send these symbol to controller <  and >

    Thursday, October 10, 2019 1:57 PM

All replies

  • User-474980206 posted

    You can, what makes you think you cannot. As the sample controller code does not use the passed data, use the debugger to see see the data.

    Thursday, October 10, 2019 2:04 PM
  • User475983607 posted

    You're mistaken.  AJAX passes "<".  This problem is your file path is invalid.  Perhaps try firing up the debugger and check your work.

    Thursday, October 10, 2019 2:10 PM
  • User-1634604574 posted

    till now i didn' understand what to do to solve this issue

    Thursday, October 10, 2019 6:32 PM
  • User-17257777 posted

    Hi zhyanadil.it@gmail.com,

    You can use F12 bowser develop tool to check If this is any error in it. I tested your codes and found the error as below:

    A potentially dangerous Request.Form value was detected from the client (f=&quot;&lt;pp&gt;&quot;).

    Since the “<” and ”>” are HTML codes and they may cause XSS (cross-site scripting), which is by default prevented in MVC, so you couldn’t get them in the controller. 

    One way is decorating the controller method with [ValidateInput(false)] and the other is decorating the ViewModel attribute with [AllowHtml]

    For more details, you can refer to:


    Best Regards,

    jiadong Meng

    Friday, October 11, 2019 6:56 AM