public IHtmlString RegisterJsonOnClientNow(string name, IClientModel clientModel, bool requireVarDefine = true,
                                                     bool requireScriptTag = true, bool requireDomReadyBlock = true)
        {
            StringBuilder sb = new StringBuilder();

            if (requireScriptTag) { AppendScriptBeginTag(sb); }
            if (requireDomReadyBlock) { AppendScriptDomReadyBeginTag(sb); }

            InsertSpaceTag(sb);
            if (requireVarDefine) { sb.Append("var "); }
            sb.AppendFormat("{0}=new {1}.{2}({3});", name, clientModel.TargetJsonModelNameSpace, clientModel.TargetJsonModelName, clientModel.ToJson());
            InsertSpaceTag(sb);

            if (requireDomReadyBlock) { AppendScriptDomReadyEndTag(sb); }
            if (requireScriptTag) { AppendScriptEndTag(sb); }

            return new HtmlString(sb.ToString());
        }
示例#2
0
        public IHtmlString RegisterJsonOnClientNow(string name, IClientModel clientModel, bool requireVarDefine = true,
                                                   bool requireScriptTag = true, bool requireDomReadyBlock = true)
        {
            StringBuilder sb = new StringBuilder();

            if (requireScriptTag)
            {
                AppendScriptBeginTag(sb);
            }
            if (requireDomReadyBlock)
            {
                AppendScriptDomReadyBeginTag(sb);
            }

            InsertSpaceTag(sb);
            if (requireVarDefine)
            {
                sb.Append("var ");
            }
            sb.AppendFormat("{0}=new {1}.{2}({3});", name, clientModel.TargetJsonModelNameSpace, clientModel.TargetJsonModelName, clientModel.ToJson());
            InsertSpaceTag(sb);

            if (requireDomReadyBlock)
            {
                AppendScriptDomReadyEndTag(sb);
            }
            if (requireScriptTag)
            {
                AppendScriptEndTag(sb);
            }

            return(new HtmlString(sb.ToString()));
        }