Ive created a simple MVC controller action that creates a simple ics (calendar) item and sends it back through the controller action. As follows:
    public object GenerateICS(int myID)
    {
        iCalendar iCal = new iCalendar();            
         Event evt = iCal.Create<Event>();
        Uri eventLink = new Uri("http://localhost:");
        evt.IsAllDay = false;
       evt.Start = new iCalDateTime(DateTime.Now);
       evt.End = new iCalDateTime(DateTime.Now.AddDays(3));
       evt.Summary = "MySummary";
       evt.Url = eventLink;
       evt.Description = "You know it";         
      Response.ContentType = "text/v-calendar";
      Response.AddHeader("content-disposition", "attachment; filename=" + "Event" + ".ics");
      iCalendarSerializer serializer = new iCalendarSerializer(iCal);
      string result = serializer.SerializeToString(iCal);
      Response.Write(result);          
        return Response;
    }
So with the website running, if I go to:
http://localhost:21312/GenerateICS?myID=1 
This will generate the ics file server side and pass it back to the client, so your receive a "Do you want to open blah.ics from localhost?". This is perfectly what I want.
My issue is how do I achieve exactly the same by executing it from javascript. I have the following ajax call:
 $.ajax({
                url: "app/GenerateICS",
                data: { myID: 1 },
                success: function (data) {
                    //call is successfully completed and we got result in data
                    alert(data);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    //some errror, some show err msg to user and log the error  
                    alert(xhr.responseText);
                }
            });
This executes the mvc controller perfectly. But it returns the ics response to the success function. How do I call the controller with ajax but have it so the file is downloaded as I describe how it does when you manually do it?
Thanks
 
     
     
     
    