Esempio n. 1
0
        /// <inheritdoc />
        public IHtmlContent Label(string expression, string labelText, object htmlAttributes)
        {
            var modelExplorer = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);

            return(GenerateLabel(
                       modelExplorer,
                       expression,
                       labelText,
                       htmlAttributes));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public IHtmlContent Display(
            string expression,
            string templateName,
            string htmlFieldName,
            object additionalViewData)
        {
            var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);

            return(GenerateDisplay(metadata,
                                   htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
                                   templateName,
                                   additionalViewData));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public IHtmlContent Editor(
            string expression,
            string templateName,
            string htmlFieldName,
            object additionalViewData)
        {
            var modelExplorer = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);

            return(GenerateEditor(
                       modelExplorer,
                       htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
                       templateName,
                       additionalViewData));
        }
Esempio n. 4
0
        public void FromStringExpression_SetsContainerAsExpected()
        {
            // Arrange
            var myModel = new TestModel {
                SelectedCategory = new Category()
            };
            var provider = new EmptyModelMetadataProvider();
            var viewData = new ViewDataDictionary <TestModel>(provider);

            viewData["Object"] = myModel;

            // Act
            var metadata = ExpressionMetadataProvider.FromStringExpression("Object.SelectedCategory",
                                                                           viewData,
                                                                           provider);

            // Assert
            Assert.Same(myModel, metadata.Container.Model);
        }
Esempio n. 5
0
        /// <inheritdoc />
        public IHtmlContent TextArea(string expression, string value, int rows, int columns, object htmlAttributes)
        {
            var modelExplorer = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);

            if (value != null)
            {
                // As a special case we allow treating a string value as a model of arbitrary type.
                // So pass through the string representation, even though the ModelMetadata might
                // be for some other type.
                //
                // We do this because thought we're displaying something as a string, we want to have
                // the right set of validation attributes.
                modelExplorer = new ModelExplorer(
                    MetadataProvider,
                    modelExplorer.Container,
                    modelExplorer.Metadata,
                    value);
            }

            return(GenerateTextArea(modelExplorer, expression, rows, columns, htmlAttributes));
        }
Esempio n. 6
0
        /// <inheritdoc />
        public string DisplayText(string expression)
        {
            var modelExplorer = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);

            return(GenerateDisplayText(modelExplorer));
        }