Exemple #1
0
        internal void Initialize()
        {
            var tagBuilder = new AngularTagBuilder(TagName);

            tagBuilder.Attributes["id"]   = Name;
            tagBuilder.Attributes["name"] = Name;

            if (IsNgForm)
            {
                tagBuilder.Attributes["ng-form"] = string.Empty;
            }
            else
            {
                tagBuilder.Attributes["ng-submit"]    = string.Format("{0}({1})", SubmitMethod, Name);
                tagBuilder.Attributes["method"]       = "POST";
                tagBuilder.Attributes["novalidate"]   = string.Empty;
                tagBuilder.Attributes["autocomplete"] = "off";
            }

            tagBuilder.MergeAttributes(_htmlAttributes, true);

            if (_render)
            {
                _helper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
            }
        }
Exemple #2
0
        public IHtmlString Label <TProperty>(Expression <Func <TModel, TProperty> > expression, IDictionary <string, object> htmlAttributes)
        {
            var    metadata    = ModelMetadata.FromLambdaExpression(expression, _helper.ViewData);
            string displayName = metadata.DisplayName ?? metadata.PropertyName;

            var tagBuilder = new AngularTagBuilder("label");

            tagBuilder.Attributes["class"] = AngularConfiguration.LabelCssClass;

            var expressionText = ExpressionHelper.GetExpressionText(expression);
            var nodeName       = GetElementIdentifier(expressionText);

            tagBuilder.MergeAttribute("for", nodeName);

            tagBuilder.SetInnerText(displayName);

            tagBuilder.MergeAttributes(htmlAttributes, true);

            return(new MvcHtmlString(tagBuilder.ToString(TagRenderMode.Normal)));
        }
Exemple #3
0
        public IHtmlString Dropdown <TProperty>(Expression <Func <TModel, TProperty> > expression, string ngOptions, string emptyElementText, IDictionary <string, object> htmlAttributes)
        {
            var metadata   = ModelMetadata.FromLambdaExpression(expression, _helper.ViewData);
            var tagBuilder = CreateTagBuilder(expression, "select", htmlAttributes, metadata);

            if (!string.IsNullOrEmpty(ngOptions))
            {
                tagBuilder.Attributes["ng-options"] = ngOptions;
            }

            if (!string.IsNullOrEmpty(emptyElementText))
            {
                var option = new AngularTagBuilder("option");
                option.Attributes["value"] = string.Empty;
                option.SetInnerText(emptyElementText);
                tagBuilder.InnerHtml = option.ToString(TagRenderMode.Normal);
            }

            return(new MvcHtmlString(tagBuilder.ToString(TagRenderMode.Normal)));
        }