顯示具有 ASP.NET MVC 標籤的文章。 顯示所有文章
顯示具有 ASP.NET MVC 標籤的文章。 顯示所有文章

2020年1月7日 星期二

RedictToActioin 傳參數到另一個 Action 的方式

TempData 來傳

範例:

XXController.cs

public ActionResult action1 () {
 TempData["message"] = "test123";
 return RedirectToAction("action2");
}

public ActionResult action2 () {
  return View();
}

action2 View(Razor)

<script>
alert(@TempData["message"]);
</script>

2012年10月8日 星期一

.NET MVC 中文檔案下載

因為每一個版本的狀況不同 ...

目前這樣測試都可以成功的把中文檔案下載下來..

string targetPath = Server.MapPath("/filesrc/") + File_Name;
string tmp_filename = File_Name;
 if (Request.Browser.Browser == "IE"|| Request.Browser.Browser == "Opera")
{
       tmp_filename = Server.UrlPathEncode(tmp_filename);
}else if (Request.Browser.Browser == "Safari" ){
       string strContentDisposition = String.Format("{0}; filename=\"{1}\"", "attachment", tmp_filename);
       Response.AddHeader("Content-Disposition", strContentDisposition);
}
 return File(targetPath, File_ContentType, tmp_filename);

瀏灠器測試版本
IE 9 及其各種相容性檢示
Chrome 22.0.1229.79 m
Firefox 15.0.1
Opera 12.02
Safari 5.1.7(7534.57.2)