How to access mvc controller in web api controller to get pdf from view

前端 未结 2 1918
终归单人心
终归单人心 2021-02-09 02:08

I created Web Api and MVC combined for single page web app. I want to call web api and render mvc controller to create pdf from view using Rotativa api. Problem is when i access

2条回答
  •  别那么骄傲
    2021-02-09 02:49

    Try by replacing your GetRequestionPdf with below one:

    public HttpResponse GetRequistionPdf(modelClass oModel)  
        {       
            HttpResponse response = HttpContext.Current.Response;
            ReportController _Report = new ReportController();
    
                    response.Clear()
                    response.ClearContent()
                    response.ClearHeaders()
                    response.Buffer = True
                    response.ContentType = "application/pdf"
                    response.AddHeader("Content-Disposition", "attachment;filename=xyz.pdf")
                    response.BinaryWrite(_Report.GetPdfBytesFormView(oModel));
                    response.End()
    
    
            return response;
        }
    

提交回复
热议问题