I am new to mvc4 . I used the below code to download file from server to client in the controller:
public ActionResult IndexSpecification(int option_id) { int cat = (int)Session["category_Name"]; int prod = (int)Session["product_ID"]; int user = (int)Session["logged_in"]; string twoinone = cat + "_" + prod; f1 = Download(twoinone); return f1; } where Download function is:
public FileResult Download( string twoinone) { var webClient = new WebClient(); byte[] fileBytes = System.IO.File.ReadAllBytes(Path.Combine(Server.MapPath("~/Download"), "a.rar")); string fileName = "Tellersoft.rar"; return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); } The call to the controller is from ajax :
$.ajax({ type: "POST", url: base_url + '/Options/IndexSpecification', data: { option_id : 2 }, //dataType: 'json', encode: true, async: false, cache: false, success: function (data, status, jqXHR) { console.log(data); }, error: function (jqXHR, textStatus, errorThrown) { if (typeof (console) != 'undefined') { alert("oooppss"); } else { alert("something went wrong"); } } }); But downloading not working .not even returning any error. Please help