1. Inside Zhou
  2. Inside.Util

Commits

Inside Zhou  committed 3f5b4e5

ViewEx无fileDownloadName参数时,不做下载操作;有则下载。

  • Participants
  • Parent commits 504fa8c
  • Branches default

Comments (0)

Files changed (2)

File Inside.Util/Properties/AssemblyInfo.cs

View file
  * 第四位数字表示不破坏兼容性的修改,如bugfix,细节优化等,当第三位数字变化时,重置为0。
  * 除非有特殊声明,否则前三位数字变化表示均不保证向后兼容。
  */
-[assembly: AssemblyVersion("2.0.1.1")]
+[assembly: AssemblyVersion("2.0.2.1")]

File Inside.Util/Web/MvcControllerBase.cs

View file
 		protected virtual ActionResult ViewEx(string viewName, string masterName, object model, string contentType, string fileDownloadName) {
 			var format = this.Request.QueryParams()[this.Key_QueryParam_Format];
 
-			if(string.IsNullOrEmpty(format) || string.Equals("html", format)) {
+			if(string.IsNullOrEmpty(fileDownloadName)) {
 				return base.View(viewName, masterName, model);
 			}
 			else {
-				if(string.IsNullOrEmpty(fileDownloadName)) {
-					fileDownloadName = string.Format("{0}.{1}", this.RouteData.GetRequiredString("action"), format);
-				}
-				else if(string.IsNullOrEmpty(Path.GetExtension(fileDownloadName))) {
+				if(string.IsNullOrEmpty(Path.GetExtension(fileDownloadName))) {
 					fileDownloadName = string.Format("{0}.{1}", fileDownloadName, format);
 				}
 
-				contentType = MIME.FindMIME(format);
+				var html = string.Empty;
 
-				var html = this.ViewToString(viewName, model);
-				switch(format.ToLower()) {
-					case "json":
-						if(model is DyObj) {
-							return this.ContentAsJson(model as DyObj);
-						}
-						else {
-							return new HttpNotFoundResult();
-						}
-					case "pdf":
-						return this.File(html.ToPdf(WebConfigurationManager.AppSettings["pdf_encryption_pwd"]), contentType, fileDownloadName);
-					default:
-						if(string.IsNullOrEmpty(contentType)) {
-							contentType = "text/html";
-						}
+				if(string.IsNullOrEmpty(format)) {
+					if(string.IsNullOrEmpty(contentType)) {
+						contentType = "text/html";
+					}
+					html = this.ViewToString(viewName, model);
+					return this.File(Encoding.UTF8.GetBytes(html), contentType, fileDownloadName);
+				}
+				else {
+					contentType = MIME.FindMIME(format);
+					if(string.IsNullOrEmpty(contentType)) {
+						contentType = "text/html";
+					}
 
-						return this.File(Encoding.UTF8.GetBytes(html), contentType, fileDownloadName);
+					switch(format.ToLower()) {
+						case "json":
+							if(model is DyObj) {
+								return this.ContentAsJson(model as DyObj);
+							}
+							else {
+								return new HttpNotFoundResult();
+							}
+						case "pdf":
+							html = this.ViewToString(viewName, model);
+							return this.File(html.ToPdf(WebConfigurationManager.AppSettings["pdf_encryption_pwd"]), contentType, fileDownloadName);
+						default:
+							html = this.ViewToString(viewName, model);
+							return this.File(Encoding.UTF8.GetBytes(html), contentType, fileDownloadName);
+					}
 				}
 			}
 		}