I have the following JavaScript code and controller action in my ASP.NET-MVC project:
Javascript:
$("#exportPPT").live('click', function (e) {
window.location.href = "/Initiative/GenerateFile" + GenerateParams();
});
C# Controller:
public ActionResult GenerateFile(MyParams myParams)
{
var template = Server.MapPath(PPT_ROOT + "/template.pptx");
IEnumerable<Order> orders = Model.GetOrders(myparams);
var pptResults = GeneratePowerpointFile(orders);
return File(pptResults.Content, "application/vnd.ms-powerpoint", pptResults.FileName);
}
But under certain conditions, let's say when orders.Count()
is 0
then instead of generating a file, I would rather have an error message back to the user saying that you have an error.
What is the best way to achieve this given the code above? I thought of changing it to an AJAX call but I wasn't sure how to download my Fie()
and package that inside a JSON request (or if that was supported).