Пример #1
0
        public Displayable WrapIn(string tagName, object attributes)
        {
            Wrapper = new System.Web.Mvc.TagBuilder(tagName);
            Wrapper.MergeAttributes(new RouteValueDictionary(attributes));

            return(this);
        }
Пример #2
0
        public ZoneHelper WrapIn(string tagName, object attributes)
        {
            Wrapper = new System.Web.Mvc.TagBuilder(tagName);
            Wrapper.MergeAttributes(new RouteValueDictionary(attributes));

            return this;
        }
Пример #3
0
        public ZoneHelper WrapIn(string tagName, object attributes, string innerHtml = null)
        {
            Wrapper = (ci) =>
            {
                var w = new System.Web.Mvc.TagBuilder(tagName);
                w.MergeAttributes(new RouteValueDictionary(attributes));
                w.InnerHtml = innerHtml;
                return(w);
            };

            return(this);
        }
Пример #4
0
        public ZoneHelper WrapIn(string tagName, object attributes, string innerHtml = null)
        {
            Wrapper = (ci) =>
            {
                var w = new System.Web.Mvc.TagBuilder(tagName);
                w.MergeAttributes(new RouteValueDictionary(attributes));
                w.InnerHtml = innerHtml;
                return w;
            };

            return this;
        }
 /// <summary>
 /// Returns the html for the date picker input, including validation attributes and message.
 /// </summary>
 /// <param name="helper">
 /// The html helper.
 /// </param>
 /// <param name="metadata">
 /// The meta data of the property to display the date for.
 /// </param>
 /// <param name="name">
 /// The fully qualified name of the property.
 /// </param>
 /// <returns></returns>
 private static string DatePickerInput(System.Web.Mvc.HtmlHelper helper, System.Web.Mvc.ModelMetadata metadata, string name)
 {
     // Construct the input
     System.Web.Mvc.TagBuilder input = new System.Web.Mvc.TagBuilder("input");
     input.AddCssClass("datepicker-input");
     input.MergeAttribute("type", "text");
     input.MergeAttribute("id", System.Web.Mvc.HtmlHelper.GenerateIdFromName(name));
     input.MergeAttribute("autocomplete", "off");
     input.MergeAttribute("name", name);
     input.MergeAttributes(helper.GetUnobtrusiveValidationAttributes(name, metadata));
     if (metadata.Model != null)
     {
         input.MergeAttribute("value", ((DateTime)metadata.Model).ToShortDateString());
     }
     // Return the html
     return(input.ToString());
 }
Пример #6
0
        /// <summary>
        /// 一个控件
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="expression"></param>
        /// <param name="attrs"></param>
        /// <returns></returns>
        public static MvcHtmlString LayInputFor <TModel, TResult>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TResult> > expression, object attrs = null) where TModel : new()
        {
            var model = htmlHelper.ViewData.Model == null ? new TModel() : htmlHelper.ViewData.Model;

            var value   = model == null ? default(TResult) : expression.Compile()(model);
            var member  = expression.Body as MemberExpression;
            var proname = "";

            if (member != null)
            {
                proname = member.Member.Name;
            }
            else
            {
                throw new ArgumentException(
                          "'" + expression + "': is not a valid expression for this method");
            }
            //字段类型
            var propInfo   = model.GetType().GetProperty(proname);
            var inputModel = LayHtmlHelper.GetPropertyAttributte <InputAttribute>(propInfo) ?? new InputAttribute();
            var des        = LayHtmlHelper.GetPropertyAttributte <DescriptionAttribute>(propInfo);
            var attrDic    = LayHtmlHelper.GetAttributtes(inputModel);

            if (attrs != null)
            {
                attrDic.Merge(attrs.ToDictionary(), true);
            }
            //判断是否有name属性
            if (!attrDic.ContainsKey("name"))
            {
                attrDic.Add("name", proname);
            }
            //id 属性
            if (!attrDic.ContainsKey("id"))
            {
                attrDic.Add("id", proname);
            }
            //LayFilter
            if (!attrDic.ContainsKey("LayFilter"))
            {
                attrDic.Add("LayFilter", proname);
            }

            TagBuilder tagBuilder = new TagBuilder("input");

            tagBuilder.MergeAttributes(attrDic);
            var mainHtml = new TagBuilder("div");

            mainHtml.AddCssClass("layui-form-item");
            var lab = new TagBuilder("label");

            lab.AddCssClass("layui-form-label");
            lab.InnerHtml = des == null ? "" : des.Description;
            var div2 = new TagBuilder("div");

            if (inputModel.DisplayType == DisplayType.block)
            {
                div2.AddCssClass("layui-input-block");
            }
            if (inputModel.DisplayType == DisplayType.inline)
            {
                div2.AddCssClass("layui-input-inline");
            }
            div2.InnerHtml     = tagBuilder.ToString();
            mainHtml.InnerHtml = lab.ToString() + div2.ToString();
            return(new MvcHtmlString(mainHtml.ToString()));

            /*
             * < div class="layui-form-item">
             *  <label class="layui-form-label">输入框</label>
             *  <div class="layui-input-block">
             *       <input type = "text" name="" placeholder="请输入" autocomplete="off" class="layui-input">
             *  </div>
             * </div>
             */
        }
Пример #7
0
        private static MvcHtmlString CKEditorHelper(HtmlHelper htmlHelper, ModelMetadata modelMetadata, string name, IDictionary <string, object> rowsAndColumns, IDictionary <string, object> htmlAttributes, string ckEditorConfigOptions)
        {
            string fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            if (String.IsNullOrEmpty(fullName))
            {
                throw new ArgumentException("string parameter is null or empty", "name");
            }

            TagBuilder textAreaBuilder = new TagBuilder("textarea");

            textAreaBuilder.GenerateId(fullName);
            textAreaBuilder.MergeAttributes(htmlAttributes, true);
            textAreaBuilder.MergeAttribute("name", fullName, true);
            string style = "";

            if (textAreaBuilder.Attributes.ContainsKey("style"))
            {
                style = textAreaBuilder.Attributes["style"];
            }
            if (string.IsNullOrWhiteSpace(style))
            {
                style = "";
            }
            style += string.Format("height:{0}em; width:{1}em;", rowsAndColumns["rows"], rowsAndColumns["cols"]);
            textAreaBuilder.MergeAttribute("style", style, true);
            // If there are any errors for a named field, we add the CSS attribute.
            ModelState modelState;

            if (htmlHelper.ViewData.ModelState.TryGetValue(fullName, out modelState) && modelState.Errors.Count > 0)
            {
                textAreaBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
            }

            textAreaBuilder.MergeAttributes(htmlHelper.GetUnobtrusiveValidationAttributes(name));

            string value;

            if (modelState != null && modelState.Value != null)
            {
                value = modelState.Value.AttemptedValue;
            }
            else if (modelMetadata.Model != null)
            {
                value = modelMetadata.Model.ToString();
            }
            else
            {
                value = String.Empty;
            }

            // The first newline is always trimmed when a TextArea is rendered, so we add an extra one
            // in case the value being rendered is something like "\r\nHello".
            textAreaBuilder.SetInnerText(Environment.NewLine + value);

            TagBuilder scriptBuilder = new TagBuilder("script");

            scriptBuilder.MergeAttribute("type", "text/javascript");
            if (string.IsNullOrEmpty(ckEditorConfigOptions))
            {
                ckEditorConfigOptions = string.Format("{{ width:'{0}em', height:'{1}em', CKEDITOR.config.allowedContent : true }}", rowsAndColumns["cols"], rowsAndColumns["rows"]);
            }
            if (!ckEditorConfigOptions.Trim().StartsWith("{"))
            {
                ckEditorConfigOptions = "{" + ckEditorConfigOptions;
            }
            if (!ckEditorConfigOptions.Trim().EndsWith("}"))
            {
                ckEditorConfigOptions += "}";
            }
            scriptBuilder.InnerHtml = string.Format(" $('#{0}').ckeditor({1}).addClass('{2}'); ",
                                                    fullName,
                                                    ckEditorConfigOptions,
                                                    CK_Ed_Class
                                                    );
            return(MvcHtmlString.Create(textAreaBuilder.ToString() + "\n" + scriptBuilder.ToString()));
        }