Example #1
0
        public static HtmlString Foreach(object model, string collectionFieldName, Func <dynamic, RepeatedHtmlElement> template)
        {
            var sb = new StringBuilder();

            bool first = true;

            var collection = Reflector.GetValue(model, collectionFieldName) as IEnumerable <object>;

            if (collection == null)
            {
                throw new ArgumentException(string.Format("The field '{0}' is not IEnumerable<object>", collectionFieldName));
            }

            foreach (dynamic el in collection)
            {
                RepeatedHtmlElement repeated = template(el);

                ComposableHtmlString s = first ? repeated.AsFirstElement(el) : repeated.AsElement(el);

                sb.AppendLine(s.ToString());

                first = false;
            }

            string htmlString = sb.ToString();

            return(new ComposableHtmlString(htmlString, collectionFieldName));
        }
Example #2
0
        private string Template(object model, IDictionary <string, string> allAtts)
        {
            var atts = allAtts.Select(attr => string.Format("{0}=\"{1}\"", attr.Key, attr.Value)).ToList();

            var attrSb = string.Join(" ", atts);

            return(string.Format("<li {0}>{1}</li>", attrSb, Reflector.GetValue(model, _textFieldName)));
        }
Example #3
0
 private Dictionary <string, string> GetPropertyValues(object model)
 {
     return(_attributes.ToDictionary(a => a.Key, a => Reflector.GetValue(model, a.Value).ToString()));
 }