0

I am trying to post whole form data by ajax. My sample code is here:

$.ajax({
            url: "@Url.Action("SaveTPGeneralInfo", "Techpack", new { area = "OMS" })",
            data: $('#FormId').serializeArray(),
            type: 'POST',
            success: function (data) {
                if (data) {
                   // .....
                }
            },
            error: function (error) {
                // .....
            }
        });

As I am working in asp.net mvc 4, I am catching the data like this:

public int SaveTPGeneralInfo(oms_techpack oms_techpack) 
    {
        try
        {
            return 1;
        }
        catch (Exception ex)
        {
            return 0;
        }
    }

Here some data contains special characters (like &, @). Those characters are passed as encrypted(like for '&' it passes 'amp;'). How can I get the original data that contains special characters. Need help...

raisul
  • 640
  • 1
  • 5
  • 26
  • Did you check this post [Decoding in asp.net 4.0 - Special Characters](http://stackoverflow.com/questions/16163605/decoding-in-asp-net-4-0-special-characters). Your question seems like it is not about encoding because as far as I know jQuery uses the encoding of the web page that invokes the AJAX method to interpret the received data. So problem must be with decoding, in ASP part of your application. And be sure everything is UTF-8 in the first place. – effe Jan 02 '14 at 09:42

1 Answers1

0

I create 2 methods that I run the result through to get back the original.

public string Decode(string value)
    {
        return (value)
            .Replace(""", "\"")
            .Replace("&lt;", "<")
            .Replace("&gt;", ">")
            .Replace("&#39;", "&")
            .Replace("&#64;", "@");
    }

    public string Encode(string value)
    {
        return (value)
          .Replace("\"", "&quot;")
          .Replace("'", "''")
          .Replace("<", "&lt;")
          .Replace(">", "&gt;")
          .Replace("&", "&#39;")
          .Replace("@", "&#64;");
    }

you can pass the string you want converted to one of these and you should get what you want.

Matt Bodily
  • 6,403
  • 4
  • 29
  • 48