12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper
- , Expression<Func<TModel, TProperty>> expression
- , IDictionary<string, object> attributes = null
- , FileType fileType = FileType.ALL)
- {
- if (expression == null)
- {
- throw new ArgumentNullException("expression");
- }
- ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, TProperty>(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("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />\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<string, object> attributes = null, FileType fileType = FileType.ALL)
- {
- StringBuilder sb = new StringBuilder();
- UrlHelper urlhelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
- sb.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />\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<string, object> attributes = null, FileType fileType = FileType.ALL)
- {
- StringBuilder sb = new StringBuilder();
- UrlHelper urlhelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
- sb.AppendFormat("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />\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<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper
- , Expression<Func<TModel, TProperty>> expression
- , IDictionary<string, object> attributes = null)
- {
- if (expression == null)
- {
- throw new ArgumentNullException("expression");
- }
- //ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, TProperty>(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));
- }
- }
- }
|