I am new to using ASP.NET MVC 4 with Web Api.
I want to allow user to download a file, this file I will be creating on the server side. For creating the file I have managed to get hold of the following code
[ActionName("Export")] public HttpResponseMessage PostExportData(SomeModel model) { string csv = _service.GetData(model); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StringContent(csv); //a text file is actually an octet-stream (pdf, etc) result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); //we used attachment to force download result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = "file.csv"; return result; } HOW TO CALL THIS WEB API METHOD USING JQUERY ?
But I am not sure of how to call this web api using jquery and make it return me a file, with a "save as / open" option that you normally get when downloading any file.
Can some one please help me and guide me in how to make the call and download the file. Thanks.