Пример #1
0
        public static HtmlAttributes Data(this HtmlAttributes attributes, string key, object value)
        {
            var actualKey = key.StartsWith("data-") ? key : "data-" + key;

            attributes.Add(actualKey, value.SerializeToJson());
            return(attributes);
        }
Пример #2
0
        /// <summary>
        ///   Adds a data-* attribute to the tag with the value serialized to JSON.
        /// </summary>
        /// <param name = "attributes">The attributes to which to add the data.</param>
        /// <param name = "key">The name of the attribute.</param>
        /// <param name = "value">The value to be serialized to JSON and inserted into the attribute's value.</param>
        /// <returns>The modified <see cref = "HtmlAttributes" /> instance.</returns>
        public static HtmlAttributes Data(
            this HtmlAttributes attributes,
            string key,
            string value)
        {
            var actualKey = key.StartsWith("data-") ? key : "data-" + key;

            attributes.Add(actualKey, value);
            return(attributes);
        }