public static string ToFormPost(this NameValueCollection collection)
        {
            var          builder          = new StringBuilder(128);
            const string inputFieldFormat = "<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />\n";

            foreach (string name in collection)
            {
                var values = collection.GetValues(name);
                var value  = values.First();
                value = Encoder.HtmlEncode(value);
                builder.AppendFormat(inputFieldFormat, name, value);
            }

            return(builder.ToString());
        }
        object BuildModel(CommonViewModel model, string page, ICollection <string> stylesheets, ICollection <string> scripts)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (stylesheets == null)
            {
                throw new ArgumentNullException("stylesheets");
            }
            if (scripts == null)
            {
                throw new ArgumentNullException("scripts");
            }

            var applicationPath = new Uri(model.SiteUrl).AbsolutePath;

            if (applicationPath.EndsWith("/"))
            {
                applicationPath = applicationPath.Substring(0, applicationPath.Length - 1);
            }

            var json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.None, settings);

            var additionalStylesheets = BuildTags("<link href='{0}' rel='stylesheet'>", applicationPath, stylesheets);
            var additionalScripts     = BuildTags("<script src='{0}'></script>", applicationPath, scripts);

            return(new {
                siteName = Encoder.HtmlEncode(model.SiteName),
                applicationPath,
                model = Encoder.HtmlEncode(json),
                page,
                stylesheets = additionalStylesheets,
                scripts = additionalScripts
            });
        }