コード例 #1
0
        /*==================================================== */

        private static MvcHtmlString staticControlHelper(HtmlHelper htmlHelper, ModelMetadata metadata, string name, IDictionary <string, object> htmlAttributes)
        {
            string fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            if (String.IsNullOrEmpty(fullName))
            {
                throw new ArgumentException("必須給這些 Input List 一個 Name", "name");
            }

            string valueStr = (string)HelperUtils.GetModelStateValue(htmlHelper, fullName, typeof(string));

            if (valueStr == null)
            {
                object value = htmlHelper.ViewData.Eval(name);
                valueStr = (value != null ? value.ToString() : null);
            }

            var input = new TagBuilder("input");

            input.GenerateId(fullName);
            input.Attributes["type"] = "hidden";
            input.Attributes["name"] = fullName;
            input.MergeAttribute("value", valueStr, true);

            var pre = new TagBuilder("pre");

            pre.InnerHtml = HttpUtility.HtmlEncode(valueStr);
            pre.MergeAttributes(htmlAttributes);

            return(new MvcHtmlString(input.ToString(TagRenderMode.SelfClosing) + pre.ToString(TagRenderMode.Normal)));
        }
コード例 #2
0
        /*==================================================== */

        private static MvcHtmlString staticControlHelper(HtmlHelper htmlHelper, ModelMetadata metadata, string name, object value, string format, IDictionary <string, object> htmlAttributes)
        {
            string fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            if (String.IsNullOrEmpty(fullName))
            {
                throw new ArgumentException("必須給這些 Input 一個 Name", "name");
            }


            string valueStr = (string)HelperUtils.GetModelStateValue(htmlHelper, fullName, typeof(string));

            if (valueStr == null)
            {
                valueStr = htmlHelper.FormatValue(value, format);
            }

            return(BsStaticControl(htmlHelper, name, valueStr, valueStr, htmlAttributes));
        }