0

MVC4, C#.NET 4.5: requirement : download text file to local system on the click of the button when passing very long string to the controller action. Below works fine, but truncates very long string, so not all data get to controller. How to overcome this limitation? Many thanks

VIEW

$("#myBtn").click(function () {

var myId = 123;
var  myValues = “1,A,1/01/2014;2,B,2/02/2014; …….  ”;  // string of about 10K characters

var actionUrl = '@Html.Raw(@Url.Action("DownloadMyFile", "Home", new { parm1 = "PLACEHOLDER1", parm2 = "PLACEHOLDER2" }))';

var url1 = actionUrl.replace('PLACEHOLDER1', myId);
var url2 = url1.replace('PLACEHOLDER2', myValues);

window.location = url2; 
});

CONTROLLER

public FileResult DownloadMyFile ((int parm1 = 0, string parm2 = null)
{
// HERE parm2 HAS ONLY 5237 CHARACTERS OUT OF VERY LONG STRING

//…… processing code here
return File(_fileBytes, "text", "MyFile.txt");  // Download to local system, 
}
Karen Slon
  • 233
  • 1
  • 4
  • 16

1 Answers1

0

See What is the maximum length of a URL in different browsers?. Short answer - don't use long strings as GET request params. If you need to send long strings on server, use POST request for that case.

Community
  • 1
  • 1
Frank59
  • 3,141
  • 4
  • 31
  • 53
  • Thanks, but I need to know How to use POST in my case when I Need to return FileResult from Controller to Browser. I used to try Ajax Post with no success. It does Not return FileResult directly to browser to be available for Download. Thanks again – Karen Slon Apr 23 '15 at 15:44