Exemplo n.º 1
0
        public static string Object(HtmlHelper html)
        {
            ModelMetadata metadata = html.Context.ViewData.Metadata;
            object        model    = html.Context.ViewData.Model;
            Type          type     = html.Context.ViewData.Template.Type;

            if (model == null)
            {
                return(metadata.NullDisplayText);
            }

            if (html.Context.ViewData.Template.Depth > 1)
            {
                return(metadata.GetDisplayText(model));
            }

            StringBuilder builder = new StringBuilder();

            foreach (ModelMetadata property in metadata.Properties
                     .Where(pm => pm.Visible).OrderBy(pm => pm.FieldOrder))
            {
                object propertyValue = (model == null) ? null : property.GetModel(model);
                if (!metadata.HideSurroundingChrome)
                {
                    builder.Append(LabelExtensions.Render(html.Context, property.PropertyName, property));
                }

                builder.Append(html.Templates.Render(DataBoundControlMode.ReadOnly,
                                                     property, null, property.PropertyName, propertyValue));
            }
            return(builder.ToString());
        }
Exemplo n.º 2
0
        public static string Object(HtmlHelper html)
        {
            ValidationHelper validation = new ValidationHelper(html.Context);

            ModelMetadata metadata = html.Context.ViewData.Metadata;
            object        model    = html.Context.ViewData.Model;
            Type          type     = html.Context.ViewData.Template.Type;

            if (model == null)
            {
                return(metadata.NullDisplayText);
            }

            if (html.Context.ViewData.Template.Depth > 1)
            {
                return(metadata.GetDisplayText(model));
            }

            StringBuilder builder = new StringBuilder();

            foreach (ModelMetadata property in metadata.Properties
                     .Where(pm => pm.Visible).OrderBy(pm => pm.FieldOrder))
            {
                object propertyValue = (model == null) ? null : property.GetModel(model);
                string elementName   = html.Context.ViewData.Template.GetHtmlElementName(property.PropertyName);

                if (!property.HideSurroundingChrome)
                {
                    builder.Append(LabelExtensions.Render(html.Context, property.PropertyName, property));
                }

                builder.Append(html.Templates.Render(W.DataBoundControlMode.Edit,
                                                     property, null, property.PropertyName, propertyValue));

                validation.Messages(elementName, (errors) => {
                    builder.Append(new HtmlElementBuilder("ul",
                                                          new { @class = "validation-error" },
                                                          string.Join(Environment.NewLine, errors.Select(
                                                                          error => new HtmlElementBuilder("li", null, error.Message).ToString()
                                                                          ).ToArray())
                                                          ));
                });
            }
            return(builder.ToString());
        }