public static HtmlString ToJavaScriptTag(this object obj, string varName)
 {
     string value = "<script type='text/javascript'>\r\n\tvar {0}={1};\r\n</script>\r\n";
     AtomJavaScriptSerializer js = new AtomJavaScriptSerializer(null, false);
     value = string.Format(value, varName, js.Serialize(obj));
     return new HtmlString(value);
 }
Example #2
0
        public static HtmlString ToJavaScriptTag(this object obj, string varName)
        {
            string value = "<script type='text/javascript'>\r\n\tvar {0}={1};\r\n</script>\r\n";
            AtomJavaScriptSerializer js = new AtomJavaScriptSerializer(null, false);

            value = string.Format(value, varName, js.Serialize(obj));
            return(new HtmlString(value));
        }
Example #3
0
        /// <summary>
        /// Creates JavaScript Variable with Provided name for Model
        /// </summary>
        /// <param name="name"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static HtmlResource RegisterPageScriptModel(string name, object model)
        {
            var s = new HtmlScriptResource();
            AtomJavaScriptSerializer js = new AtomJavaScriptSerializer(null);

            s.Code = "var " + name + " = " + js.Serialize(model) + ";";
            return(s);
        }