Ejemplo n.º 1
0
        static internal string RenderUpdateInfoI(HtmlHelper htmlHelper, IUpdateModel updateModel, ref string prefix, string[] expressions, string template = null, Type typeToUse = null, bool noOutput = false)
        {
            bool prefixEmpty = false;
            bool sameType    = false;

            if (typeToUse == null)
            {
                typeToUse = updateModel.GetType();
            }
            if (string.IsNullOrWhiteSpace(prefix))
            {
                if (string.IsNullOrWhiteSpace(htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix))
                {
                    prefixEmpty = true;
                    prefix      = ".$$";
                }
                else
                {
                    prefix = "$$";
                }
            }
            else
            {
                prefix = prefix + ".$$";
            }
            if (template != null)
            {
                prefix = prefix + template;
            }
            else
            {
                int index = 0;
                if (htmlHelper.ViewData.ContainsKey(prefix))
                {
                    UpdateInfo infos = (htmlHelper.ViewData[prefix]) as UpdateInfo;
                    index    = infos.CurrIndex;
                    sameType = infos.CurrType == typeToUse;
                }
                htmlHelper.ViewData[prefix] = new UpdateInfo {
                    CurrIndex = index + 1, CurrType = typeToUse
                };
                prefix = prefix + index.ToString();
            }
            if (noOutput)
            {
                return(null);
            }
            StringBuilder sb = new StringBuilder();

            foreach (string expr in expressions)
            {
                if (sb.Length != 0)
                {
                    sb.Append(",");
                }
                sb.Append(expr);
            }
            string res = null;

            if (sameType)
            {
                res = SafeHiddenF(htmlHelper, (prefixEmpty ? "updatemodel" + prefix : prefix),
                                  string.Empty).ToString()
                      +
                      SafeHiddenF(htmlHelper, (prefixEmpty ? "updatemodel" + prefix : prefix) + ".f$ields",
                                  sb.ToString()).ToString();
            }
            else
            {
                res = SafeHiddenU(htmlHelper, (prefixEmpty ? "updatemodel" + prefix : prefix),
                                  typeToUse).ToString()
                      +
                      SafeHiddenF(htmlHelper, (prefixEmpty ? "updatemodel" + prefix : prefix) + ".f$ields",
                                  sb.ToString()).ToString();
            }



            return(res);
        }