You can render the component in a PartialView and use AJAX to update/replace it. In your main view call RenderHead and in your partial view call RenderBody. Share model creating code in your controller between main and partial views so that you can pass same model to both views.
public ActionResult DownloadPdf() { var inputFile = "SomeDocument.docx"; var outputStream = new MemoryStream(); var documentConverter = new DocumentConverter(inputFile); documentConverter.ConvertTo(outputStream, DocumentFormat.Pdf); //Rewind the stream which contains the converted Pdf now. outputStream.Position = 0; return File( outputStream, System.Net.Mime.MediaTypeNames.Application.Pdf, "Result.pdf"); }
public ActionResult SomeAction() { //Call your existing partial view and convert it to string var html = RenderToString(PartialView("SomeView")); var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(html)); var outputStream = new MemoryStream(); var documentConverter = new DocumentConverter(inputStream, DocumentFormat.Html); documentConverter.ConvertTo(outputStream, DocumentFormat.Pdf); //Rewind the stream which contains the converted Pdf now. outputStream.Position = 0; return File( outputStream, System.Net.Mime.MediaTypeNames.Application.Pdf, "Result.pdf"); } private string RenderToString(PartialViewResult partialView) { var rc = Request.RequestContext; var controllerName = rc.RouteData.Values["controller"].ToString(); var controller = (ControllerBase)ControllerBuilder.Current .GetControllerFactory().CreateController(rc, controllerName); var controllerContext = new ControllerContext(rc, controller); var view = ViewEngines.Engines.FindPartialView(controllerContext, partialView.ViewName).View; var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) using (var tw = new HtmlTextWriter(sw)) { view.Render( new ViewContext(controllerContext, view, partialView.ViewData, partialView.TempData, tw), tw ); } return sb.ToString(); }
Trouble logging in? Simply enter your email address OR username in order to reset your password.
For faster and more reliable delivery, add notify@gleamtech.com to your trusted senders list in your email software.