I am doing a simple $.ajax request:
$.ajax({
type: "POST",
url: "/Run/" + param1 + "/" + param2,
dataType: 'html',
error: function(error) {
},
success: function(html) {
}
});
If my param2 value is like http://localhost/pub/file?val1=Some Text&val2=Some Text then encoding done using escape(param2), encodeURI(param2), encodeURIComponent(param2) doesn’t help. And I get following ERROR –>
HTTP Error 400.0 – Bad Request
ASP.NET detected invalid characters in the URL
My Questions –>
- How should I encode param2 ?
- What is the maximum length of request URL in $.ajax call ?
- Is request URL max length dependent on type of browser from which request is made ?
- I have observed that if I use Ajax.ActionLink then I do not need to encode the parameters passed to action and I can pass parameters with length > 10,000 characters as well. But I do not know how to make an explicit call using Ajax.ActionLink from my java script. I need to click on that actionlink to make call through Ajax.ActionLink.
Benefits of Ajax.actionLink–>
Please see the length of parameter categoryName passed to action using Ajax.ActionLink (This is mine observation)


Such big parameters should be posted and not sent in the URL.
This will automatically handle parameter encoding. If you absolutely insist on sending them in the url you may declare a global javascript variable that will hold the url to call: