using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Web.Controls.Mvc; namespace System.Web.Mvc { public static class UploaderExtensions { public static MvcHtmlString UploaderFor(this HtmlHelper htmlHelper , Expression> expression , IDictionary attributes = null , FileType fileType = FileType.ALL) { if (expression == null) { throw new ArgumentNullException("expression"); } ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); UrlHelper urlhelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); sb.AppendFormat("\r\n", urlhelper.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/OwnUploadify.css")); sb.Append(Bowin.Web.Controls.Mvc.Uploader.CreateControl(new uploaderOption() { Name = fullHtmlFieldName, MainTableID = modelMetadata.Model }, attributes, fileType).Render(urlhelper)); return MvcHtmlString.Create(sb.ToString()); } public static MvcHtmlString Uploader(this HtmlHelper htmlHelper, uploaderOption _uploaderOption, IDictionary attributes = null, FileType fileType = FileType.ALL) { StringBuilder sb = new StringBuilder(); UrlHelper urlhelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); sb.AppendFormat("\r\n", urlhelper.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/OwnUploadify.css")); sb.Append(Bowin.Web.Controls.Mvc.Uploader.CreateControl(_uploaderOption, attributes, fileType).Render(urlhelper)); return MvcHtmlString.Create(sb.ToString()); } public static MvcHtmlString Uploader(this HtmlHelper htmlHelper, IDictionary attributes = null, FileType fileType = FileType.ALL) { StringBuilder sb = new StringBuilder(); UrlHelper urlhelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); sb.AppendFormat("\r\n", urlhelper.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/OwnUploadify.css")); sb.Append(Bowin.Web.Controls.Mvc.Uploader.CreateControl(new uploaderOption(), attributes, fileType).Render(urlhelper)); return MvcHtmlString.Create(sb.ToString()); } public static MvcHtmlString SingleUploaderFor(this HtmlHelper htmlHelper , Expression> expression , IDictionary attributes = null) { if (expression == null) { throw new ArgumentNullException("expression"); } //ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); TagBuilder tabBuilder = new TagBuilder("input"); tabBuilder.MergeAttribute("type", "file"); tabBuilder.MergeAttribute("name", fullHtmlFieldName); if (attributes != null) { tabBuilder.MergeAttributes(attributes); } return MvcHtmlString.Create(tabBuilder.ToString(TagRenderMode.SelfClosing)); } } }