public void LabelForWithArrayExpression()
        { // Dev10 Bug #905780
            // Arrange
            HtmlHelper<Cart> html = new HtmlHelper<Cart>(viewContext.Object, viewDataContainer.Object);

            // Act
            MvcHtmlString result = html.LabelFor(cart => cart.Products[0].Id, null, null, metadataProvider.Object);

            // Assert
            Assert.Equal(@"<label for=""Products_0__Id"">Id</label>", result.ToHtmlString());
        }
Example #2
0
        private static String WrapInFormGroup <TModel, TValue>(HtmlHelper <TModel> helper, Expression <Func <TModel, TValue> > expression, String title, String controlHtml, Boolean addClearButton = false, String clearButtonClass = "btn-default", String helpText = null, string helpTextPosition = "right", string addonText = null, string addonPosition = "right")
        {
            var resultControlHtml = controlHtml;
            var html       = new StringBuilder();
            var formGroup  = new TagBuilder("div");
            var inputHtml  = new StringBuilder();
            var inputGroup = new TagBuilder("div");

            inputGroup.AddCssClass("input-group");

            if (!String.IsNullOrEmpty(addonText) || addClearButton)
            {
                if (!String.IsNullOrEmpty(addonText) && addonPosition == "left")
                {
                    inputHtml
                    .Append("<span class=\"input-group-addon\">")
                    .Append(addonText)
                    .Append("</span>");
                }

                inputHtml.Append(controlHtml);

                if (!String.IsNullOrEmpty(addonText) && addonPosition == "right")
                {
                    inputHtml
                    .Append("<span class=\"input-group-addon\">")
                    .Append(addonText)
                    .Append("</span>");
                }

                if (addClearButton)
                {
                    inputHtml
                    .Append("<span class=\"input-group-btn\">")
                    .Append("<button class=\"input-clear btn " + clearButtonClass + "\" type=\"button\">")
                    .Append("<i class=\"fa fa-fw fa-times\"></i>")
                    .Append("</button>")
                    .Append("</span>");
                }


                inputGroup.InnerHtml = inputHtml.ToString();
                resultControlHtml    = inputGroup.ToString();
            }

            formGroup.AddCssClass("form-group");

            if (!String.IsNullOrEmpty(title))
            {
                html = html.Append(helper.LabelFor(expression, title, new { @class = "control-label" }).ToHtmlString());
            }
            else if (title == String.Empty)
            {
                html = html.Append("<label class='control-label'>&nbsp;</label>");
            }

            formGroup.InnerHtml = html
                                  .Append(String.IsNullOrEmpty(helpText) ? null : "<a role='button' tabindex='0' class='help-tooltip' data-toggle='popover' data-placement='" + helpTextPosition + "' data-trigger='focus' data-content='" + helpText + "'><i class='fa fa-fw fa-question-circle'></i></a>")
                                  .Append(resultControlHtml)
                                  .Append(helper.ValidationMessageFor(expression).ToHtmlString())
                                  .ToString();

            return(formGroup.ToString());
        }
        public void LabelForWithNestedClass()
        { // Dev10 Bug #936323
            // Arrange
            HtmlHelper<NestedProduct> html = new HtmlHelper<NestedProduct>(viewContext.Object, viewDataContainer.Object);

            // Act
            MvcHtmlString result = html.LabelFor(nested => nested.product.Id, null, null, metadataProvider.Object);

            //Assert
            Assert.Equal(@"<label for=""product_Id"">Id</label>", result.ToHtmlString());
        }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="htmlHelper"></param>
 /// <param name="expression"></param>
 /// <returns></returns>
 public static MvcHtmlString BootstrapLabelFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression)
 {
     return(htmlHelper.LabelFor(expression, new { @class = "control-label" }));
 }
 public void LabelForNullExpressionThrows()
 {
     // Act & Assert
     Assert.ThrowsArgumentNull(
         () => html.LabelFor((Expression <Func <Object, Object> >)null),
         "expression");
 }
Example #6
0
 public static MvcHtmlString LabelForVN <TModel, TValue>(this HtmlHelper <TModel> html, string prefix, Expression <Func <TModel, TValue> > expression, string suffix)
 {
     return(html.LabelFor(expression, prefix + html.VN((expression.Body as MemberExpression).Member.Name) + suffix));
 }
Example #7
0
        public static MvcHtmlString ImagePickerFor <TModel, TPropertyImageKey>(this HtmlHelper <TModel> helper,
                                                                               Expression <Func <TModel, TPropertyImageKey> > expressionImageKey,
                                                                               Expression <Func <TModel, HttpPostedFileBase> > expressionImageStream,
                                                                               Func <TPropertyImageKey, string> imagePlaceHolderHtmlRetriever,
                                                                               Func <string> emptyImagePlaceHolderHtmlRetriever,
                                                                               bool includeFieldLabel = true)
        {
            string  imageKeyName            = helper.GetFullPropertyName(expressionImageKey);
            string  imageStreamName         = helper.GetFullPropertyName(expressionImageStream, true);
            string  imagePlaceHolderId      = "imgPlaceHolder" + imageStreamName;
            dynamic imageKeyValue           = ModelMetadata.FromLambdaExpression(expressionImageKey, helper.ViewData).Model;
            string  imageSelectFunctionName = imageStreamName + "file_selected";
            string  removeImageButtonId     = "buttonRemoveImage" + imageStreamName;
            string  emptyImagePlaceHolderId = "emptyImage" + imageStreamName;

            //create telerik upload
            var telerikUpload = helper.Telerik().Upload()
                                .Name(imageStreamName)
                                .Localizable("fa-IR")
                                .Multiple(false)
                                .HtmlAttributes(new { style = "float:right;" })
                                .ShowFileList(false)
                                .ClientEvents(o => o.OnSelect(imageSelectFunctionName));

            StringBuilder output = new StringBuilder();

            output.AppendFormat(
                @"<div class='t-link t-state-hover image-border'>
                    {0}
                    <div id='{1}'>{2}</div>
                    <div class='image-picker-controlpanel'>
                        <table><tr>
                            <td>{3}</td>
                            <td><button class='t-button t-button-icontext t-upload-action' type='button' id='{4}'><span class='t-icon t-delete'></span></button></td>
                        </tr></table>
                    </div>
                  </div>
                  <div id='{5}' style='display: none; visibility: hidden'>{6}</div>{7}",
                includeFieldLabel ? string.Format("<div class='image-picker-top'>{0}</div>", helper.LabelFor(expressionImageKey)) : "",
                imagePlaceHolderId,
                imagePlaceHolderHtmlRetriever(imageKeyValue),
                telerikUpload.ToHtmlString(),
                removeImageButtonId,
                emptyImagePlaceHolderId,
                emptyImagePlaceHolderHtmlRetriever(),
                helper.HiddenFor(expressionImageKey).ToHtmlString());

            output.AppendFormat
                (@"<script type='text/javascript'>
                        function {0}(e) {{
                            $('span', this).html('...تغییر تصویر');
                            $('#{1}').html('<span class=""icon16 check48-png""></span><br/>آماده بارگذاری...');
                        }}
                        $('#{2}').click(function () {{
                            $('#{1}').html($('#{3}').html());
                            var upload = $('#{4}').data('tUpload');
                            $('#{5}').attr('value', '');
                            //todo : remove it from upload control too 
                        }});
                  </script>",
                imageSelectFunctionName,
                imagePlaceHolderId,
                removeImageButtonId,
                emptyImagePlaceHolderId,
                imageStreamName,
                imageKeyName
                );

            return(new MvcHtmlString(output.ToString()));

            //this function is designed based on the following codes:
            //<div class="t-link t-state-hover image-border">
            //    <div class="image-picker-top">@Html.LabelFor(model => model.ImageFileIdentity)</div>
            //    <div id="imgPlaceHolder">@UiFunctions.ResourceImage(Model.ImageFileIdentity, Greewf.PIN.Infrastracture.Global.ImageSize.Medium)</div>
            //    <div class="image-picker-controlpanel">
            //        <table>
            //            <tr>
            //                <td>@(Html.Telerik().Upload().Name(Html.GetPropertyName(o => o.ImageFile)).Localizable("fa-IR").Multiple(false).HtmlAttributes(new { style = "float:right;" }).ShowFileList(true).ClientEvents(o => o.OnSelect("file_selected")))
            //                </td>
            //                <td>
            //                            <button class="t-button t-button-icontext t-upload-action" type="button" id="buttonRemoveImage">
            //                                <span class="t-icon t-delete"></span>
            //                            </button>
            //                </td>
            //            </tr>
            //        </table>
            //    </div>
            //</div>
            //<div id="emptyImage" style="display: none; visibility: hidden">@UiFunctions.ResourceImage(null, Greewf.PIN.Infrastracture.Global.ImageSize.Medium)</div>
            //<script type="text/javascript">
            //    function file_selected(e) {
            //        $('span', this).html('...تغییر تصویر');
            //        $('#imgPlaceHolder').html('<span class="icon16 check48-png"></span><br/>آماده بارگذاری...');
            //    }
            //    $('#buttonRemoveImage').click(function () {
            //        $('#imgPlaceHolder').html($('#emptyImage').html());
            //        var upload = $('#@Html.GetPropertyName(o => o.ImageFile)').data("tUpload");
            //        $('#@Html.GetPropertyName(o => o.ImageFileIdentity)').attr('value', '');
            //        //todo : remove it from upload control too
            //    });
            //</script>
            //@Html.HiddenFor(model => model.ImageFileIdentity)
        }
 public void ControlLabelFor <TValue>(Expression <Func <TModel, TValue> > expression, IDictionary <string, object> htmlAttributes)
 {
     EnsureHtmlAttribute(htmlAttributes, "class", "control-label");
     this.textWriter.Write(htmlHelper.LabelFor(expression, htmlAttributes));
 }
Example #9
0
 public static MvcHtmlString LabelForDirective <TModel, TValue>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TValue> > expression, object htmlAttributes)
 {
     return(helper.LabelFor(expression, htmlAttributes));
 }
        public void LabelFor()
        {
            HtmlHelper helper = new HtmlHelper();

            Assert.AreEqual("<label  for=\"x\">name</label>\r\n", helper.LabelFor("x", "name"));
        }