将html转换为mvc中的doc文件

将html转换为mvc中的doc文件

本文介绍了将html转换为mvc中的doc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            var htmlHelper = new HtmlHelper(new ViewContext(
                                     ControllerContext,
                                     new WebFormView(ControllerContext, "HACK"),
                                     new ViewDataDictionary(),
                                     new TempDataDictionary(),
                                     new StringWriter()),
                               new ViewPage());
            var otherViewHtml = htmlHelper.Action("About", "Home");

      HttpContext.Response.Clear();  
     HttpContext.Response.Charset = "";  
     HttpContext.Response.ContentType = "application/msword";  
     string strFileName = "test" + ".doc";  
     HttpContext.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);  
     StringBuilder strHTMLContent = new StringBuilder();
     strHTMLContent.Append(otherViewHtml);       
     HttpContext.Response.Write(strHTMLContent);  
     HttpContext.Response.End();  
     HttpContext.Response.Flush();
            return View();
        }

推荐答案


这篇关于将html转换为mvc中的doc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 09:45