0
我有一個與「application/msword」的ContentType呈現的視圖。對於用戶,這顯示爲下載文件。現在,我想保存這個文件服務器端。我怎麼能訪問呈現的文檔服務器端?如何在MVC中獲取ViewResult的內容?
我有一個與「application/msword」的ContentType呈現的視圖。對於用戶,這顯示爲下載文件。現在,我想保存這個文件服務器端。我怎麼能訪問呈現的文檔服務器端?如何在MVC中獲取ViewResult的內容?
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))
{
var viewContext =
new ViewContext(
filterContext.Controller.ControllerContext,
vResult.View,
vResult.ViewData,
vResult.TempData,
writer);
vResult.View.Render(viewContext, writer);
writer.Flush();
}
在服務器上,您可以使用WebClient將url請求的HTTP請求和download文件或download it in memory作爲字節數組激活。