Exemplo n.º 1
0
        /// <summary>
        /// Контрол предназначен для показа сообщения пользователю в виде HTML разметки типа div.
        /// Контрол подключает к себе CSS стили из Bootstrap.css и из MT.css и использует перечисление AlertsEnum для определения стилевого оформления.
        ///  </summary>
        /// <param name="text">Текст, который будет выведен пользователю.</param>
        /// <param name="type">Перечисление типа AlertsEnum задающее стилевое оформление сообщения.</param>

        public static MvcHtmlString AlertDirective(this HtmlHelper helper, string text, object htmlAttributes = null,
                                                   AlertTypesEnum type = AlertTypesEnum.Warning)
        {
            var alertDiv   = new TagBuilder("div");
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            AttributeManager.AddClassAttribute(attributes, type);
            AttributeManager.AddClassAttribute(attributes, "alert alert-box-width");

            alertDiv.InnerHtml = text;
            alertDiv.MergeAttributes(attributes);
            return(new MvcHtmlString(alertDiv.ToString()));
        }
Exemplo n.º 2
0
        public static MvcHtmlString ButtonDirective(this HtmlHelper htmlHelper, string text, object htmlAttributes = null,
                                                    NgModelPathOptions ngModelPathOptions = null, ButtonTypesEnum type = ButtonTypesEnum.Submit)
        {
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            if (!attributes.ContainsKey("ng-click"))
            {
                throw new Exception("There is no ng_click attribute passed to ButtonDirective.");
            }

            AttributeManager.AddButtonClassAttribute(attributes, type);

            attributes.Add("value", text);
            attributes.Add("type", "button");
            var builder = new TagBuilder("input");

            builder.MergeAttributes(attributes);
            return(MvcHtmlString.Create(builder.ToString()));
        }
Exemplo n.º 3
0
        public static MvcHtmlString TextBoxDirectiveFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                            Expression <Func <TModel, TProperty> > expression, object htmlAttributes = null,
                                                                            NgModelPathOptions ngModelPathOptions = null, ControlSizesEnum type = ControlSizesEnum.Medium,
                                                                            bool isTextArea = false)
        {
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            AttributeManager.AddTitleAttribute(attributes);

            string name = ExpressionHelper.GetExpressionText(expression);

            AttributeManager.AddNgModelAttribute(attributes, name, ngModelPathOptions);

            if (isTextArea)
            {
                return(htmlHelper.TextAreaFor(expression, attributes));
            }

            return(htmlHelper.TextBoxFor(expression, attributes));
        }
Exemplo n.º 4
0
        public static MvcHtmlString DirectiveFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                     Expression <Func <TModel, TProperty> > expression, string directiveName, object htmlAttributes = null,
                                                                     NgModelPathOptions ngModelPathOptions = null, string tagName = "div")
        {
            var    attributes    = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
            string name          = ExpressionHelper.GetExpressionText(expression);
            string containerName = String.Format("{0}.{1}", directiveName, name);

            AttributeManager.AddNgModelAttribute(attributes, name, ngModelPathOptions);

            var tagBuilder = new TagBuilder(tagName);

            tagBuilder.MergeAttribute(directiveName, "");
            tagBuilder.MergeAttribute("name", containerName);
            tagBuilder.MergeAttributes(attributes);

            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            tagBuilder.MergeAttributes(htmlHelper.GetUnobtrusiveValidationAttributes(containerName, metadata));

            return(MvcHtmlString.Create(tagBuilder.ToString()));
        }