I'm pretty new to mvc and jQuery... and to web development in general really. I recently took over control of a site designed by a developer that we had to let go and the treeview control he had used needed to be changed for reasons that I won't get into here. But basically I need to be able to have resources be download on the click event of a node in the treeview. I know how to handle the event but I can't figure out how to make the call to my mvc controller through jquery. The path to the controller function I need to call to download the resource is /Resources/DownloadResource. Here's the code for it:
public ActionResult DownloadResource(string id)
{
var resource =
_resourceService.GetResourceQuery(new Specification<Resource>(r => r.ResourceId == new Guid(id))).FirstOrDefault();
return new BinaryResult
{
FileName = resource.FileName,
ContentType = string.Format("application/{0}", Path.GetExtension(resource.FileName)).Replace(".", ""),
IsAttachment = true,
Data = System.IO.File.ReadAllBytes(resource.FilePath)
};
}
I have tried something like $.post("/Resources/DownloadResourceLink", { id: value }); and when I step through, everything is getting the correct values, but no download. Any help would definitely be appreciated!