Question

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...

No correct solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top