/// <summary>
 /// Return the html for a table cell representing a date in the calendar.
 /// </summary>
 /// <param name="date">
 /// The date to display.
 /// </param>
 /// <param name="isSelected">
 /// A value indicating if the date is selected in the calendar.
 /// </param>
 /// <param name="canSelect">
 /// A value indicating if the date can be selected.
 /// </param>
 private static string Day(DateTime date, bool isSelected, bool canSelect)
 {
     // Construct container
     System.Web.Mvc.TagBuilder day = new System.Web.Mvc.TagBuilder("div");
     day.InnerHtml = date.Day.ToString();
     // Construct table cell
     System.Web.Mvc.TagBuilder cell = new System.Web.Mvc.TagBuilder("td");
     if (!canSelect)
     {
         cell.AddCssClass("disabledDay");
     }
     else if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
     {
         cell.AddCssClass("weekendDay");
     }
     else
     {
         cell.AddCssClass("workingDay");
     }
     if (isSelected)
     {
         cell.AddCssClass("selectedDay");
     }
     cell.InnerHtml = day.ToString();
     // Return the html
     return(cell.ToString());
 }
Exemplo n.º 2
0
    private static string TableCellCheckBox(ModelMetadata metaData, string fieldName)
    {
        StringBuilder html = new StringBuilder();

        // Checkbox
        System.Web.Mvc.TagBuilder checkbox = new System.Web.Mvc.TagBuilder("input");
        checkbox.MergeAttribute("type", "checkbox");
        checkbox.MergeAttribute("name", fieldName);
        checkbox.MergeAttribute("id", fieldName);
        //checkbox.MergeAttribute("value", "true");
        checkbox.MergeAttribute("disabled", "disabled");
        checkbox.MergeAttribute("class", "checkbox");
        if (metaData.Model != null && (bool)metaData.Model)
        {
            checkbox.MergeAttribute("checked", "checked");
        }
        html.Append(checkbox.ToString(TagRenderMode.SelfClosing));
        // Build additional hidden input to address scenario where
        // unchecked checkboxes are not sent in the request.

        //System.Web.Mvc.TagBuilder hidden = new System.Web.Mvc.TagBuilder("input");
        //hidden.MergeAttribute("type", "hidden");
        //hidden.MergeAttribute("name", fieldName);
        //checkbox.MergeAttribute("id", fieldName);
        //hidden.MergeAttribute("value", "false");
        //html.Append(hidden.ToString(TagRenderMode.SelfClosing));

        // Table cell

        return(html.ToString());
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="metadata"></param>
        /// <param name="fieldName"></param>
        /// <param name="minDate"></param>
        /// <param name="maxDate"></param>
        private static string DatePickerForHelper(System.Web.Mvc.HtmlHelper helper, ModelMetadata metadata,
                                                  string fieldName, DateTime?minDate = null, DateTime?maxDate = null)
        {
            // Validate the model type is DateTime or Nullable<DateTime>
            if (!(metadata.Model is DateTime || Nullable.GetUnderlyingType(metadata.ModelType) == typeof(DateTime)))
            {
                throw new ArgumentException(string.Format(_NotADate, fieldName));
            }
            //  Validate dates
            if (minDate.HasValue && maxDate.HasValue && minDate.Value >= maxDate.Value)
            {
                throw new ArgumentException("The minimum date cannot be greater than the maximum date");
            }
            if (minDate.HasValue && metadata.Model != null && (DateTime)metadata.Model < minDate.Value)
            {
                throw new ArgumentException("The date cannot be less than the miniumum date");
            }
            if (maxDate.HasValue && metadata.Model != null && (DateTime)metadata.Model > maxDate.Value)
            {
                throw new ArgumentException("The date cannot be greater than the maximum date");
            }
            //  Construct date picker
            StringBuilder html = new StringBuilder();

            // Add display text
            html.Append(DatePickerText(metadata));
            // Add input
            html.Append(DatePickerInput(helper, metadata, fieldName));
            // Add drop button
            html.Append(ButtonHelper.DropButton());
            // Get the default date to display
            DateTime date       = DateTime.Today;
            bool     isSelected = false;

            // If a date has been provided, use it and mark it as selected
            if (metadata.Model != null)
            {
                date       = (DateTime)metadata.Model;
                isSelected = true;
            }
            // Add calendar
            html.Append(Calendar(date, isSelected, minDate, maxDate));
            // Build container
            System.Web.Mvc.TagBuilder container = new System.Web.Mvc.TagBuilder("div");
            container.AddCssClass("datepicker-container");
            // Add min and max date attributes
            if (minDate.HasValue)
            {
                container.MergeAttribute("data-mindate", string.Format("{0:d/M/yyyy}", minDate.Value));
            }
            if (maxDate.HasValue)
            {
                container.MergeAttribute("data-maxdate", string.Format("{0:d/M/yyyy}", maxDate.Value));
            }
            container.InnerHtml = html.ToString();
            // Return the html
            return(container.ToString());;
        }
        public static IHtmlString ReactInitJavaScript(string script)
        {
            var tag = new System.Web.Mvc.TagBuilder("script")
            {
                InnerHtml = script
            };

            return new HtmlString(tag.ToString());
        }
Exemplo n.º 5
0
		public static IDisposable BeginAsyncAction(this HtmlHelper helper, string actionName, RouteValueDictionary routeValues)
		{
			var id = "async" + Guid.NewGuid().ToString().Replace('-', '_');
			var url = new UrlHelper(helper.ViewContext.RequestContext).Action(actionName, routeValues);

			var tag = new System.Web.Mvc.TagBuilder("div");
			tag.Attributes["id"] = id;
			tag.AddCssClass("async loading");

			helper.ViewContext.Writer.Write(tag.ToString(TagRenderMode.StartTag));

			var asyncLoadScript = string.Format(@"<script type='text/javascript'>//<![CDATA[
jQuery(document).ready(function(){{jQuery('#{0}').load('{1}');}});//]]></script>", id, url);

			var end = tag.ToString(TagRenderMode.EndTag) + asyncLoadScript;
			
			return new WritesOnDispose(helper, end);
		}
Exemplo n.º 6
0
        public static IHtmlString ReactInitJavaScript(string script)
        {
            var tag = new System.Web.Mvc.TagBuilder("script")
            {
                InnerHtml = script
            };

            return(new HtmlString(tag.ToString()));
        }
Exemplo n.º 7
0
        public static IDisposable BeginAsyncAction(this HtmlHelper helper, string actionName, RouteValueDictionary routeValues)
        {
            var id  = "async" + Guid.NewGuid().ToString().Replace('-', '_');
            var url = new UrlHelper(helper.ViewContext.RequestContext).Action(actionName, routeValues);

            var tag = new System.Web.Mvc.TagBuilder("div");

            tag.Attributes["id"] = id;
            tag.AddCssClass("async loading");

            helper.ViewContext.Writer.Write(tag.ToString(TagRenderMode.StartTag));

            var asyncLoadScript = string.Format(@"<script type='text/javascript'>//<![CDATA[
jQuery(document).ready(function(){{jQuery('#{0}').load('{1}');}});//]]></script>", id, url);

            var end = tag.ToString(TagRenderMode.EndTag) + asyncLoadScript;

            return(new WritesOnDispose(helper, end));
        }
 /// <summary>
 /// Returns the html for the date picker display text (visible when the datepicker does not have focus)
 /// </summary>
 /// <param name="metadata">
 /// The meta data of the property to display the date for.
 /// </param>
 private static string DatePickerText(ModelMetadata metadata)
 {
     System.Web.Mvc.TagBuilder text = new System.Web.Mvc.TagBuilder("div");
     text.AddCssClass("datepicker-text");
     // Add essential stype properties
     text.MergeAttribute("style", "position:absolute;z-index:-1000;");
     if (metadata.Model != null)
     {
         text.InnerHtml = ((DateTime)metadata.Model).ToLongDateString();
     }
     // Return the html
     return(text.ToString());
 }
Exemplo n.º 9
0
    private static string CreateTableString(string header, string body, GenericTableVModel model)
    {
        StringBuilder html = new StringBuilder();

        System.Web.Mvc.TagBuilder table = new System.Web.Mvc.TagBuilder("table");
        table.MergeAttribute("class", model.Setting.Class);
        table.MergeAttribute("id", model.Setting.Id);

        table.InnerHtml = header + body;

        html.Append(table.ToString());

        return(html.ToString());
    }
Exemplo n.º 10
0
        /// <summary>
        /// Returns the html for the table header displaying the selected month, navigation buttons
        /// and days of the week.
        /// </summary>
        /// <param name="date">
        /// A date in month to display.
        /// </param>
        /// <param name="minDate">
        /// The minimum date that can be seleccted.
        /// </param>
        /// <param name="maxDate">
        /// The maximum date that can be seleccted.
        /// </param>
        private static string CalendarHeader(DateTime date, DateTime?minDate, DateTime?maxDate)
        {
            StringBuilder html = new StringBuilder();

            // Add month label and navigation buttons
            html.Append(MonthHeader(date, minDate, maxDate));
            // Add day of week labels
            html.Append(WeekHeader());
            // Construct table header
            System.Web.Mvc.TagBuilder header = new System.Web.Mvc.TagBuilder("thead");
            header.InnerHtml = html.ToString();
            // Return the html
            return(header.ToString());
        }
Exemplo n.º 11
0
 /// <summary>
 /// Returns the html for a table cell with a navigation button.
 /// </summary>
 /// <param name="className">
 /// The class name to apply to the button.
 /// </param>
 /// <param name="hide">
 /// A value indicating if the button should be rendered as hidden.
 /// </param>
 private static string NavigationButton(string className, bool hide)
 {
     // Build the button
     System.Web.Mvc.TagBuilder button = new System.Web.Mvc.TagBuilder("button");
     button.AddCssClass(className);
     button.MergeAttribute("type", "button");
     button.MergeAttribute("tabindex", "-1");
     if (hide)
     {
         button.MergeAttribute("style", "display:none;");
     }
     // Construct the table cell
     System.Web.Mvc.TagBuilder cell = new System.Web.Mvc.TagBuilder("th");
     cell.InnerHtml = button.ToString();
     // Return the html
     return(cell.ToString());
 }
Exemplo n.º 12
0
        /// <summary>
        /// Return the html for the table body representing a month in the calendar.
        /// </summary>
        /// <param name="date">
        /// A date in the month to display.
        /// </param>
        /// <param name="isSelected">
        /// A value indicating if the date should be marked as selected.
        /// </param>
        /// <param name="minDate">
        /// The minimum date that can be seleccted.
        /// </param>
        /// <param name="maxDate">
        /// The maximum date that can be seleccted.
        /// </param>
        private static string Month(DateTime date, bool isSelected, DateTime?minDate, DateTime?maxDate)
        {
            // Get the first and last days of the month
            DateTime firstOfMonth = date.FirstOfMonth();
            DateTime lastOfMonth  = date.LastOfMonth();
            // Get the first date to display in the calendar (may be in the previous month)
            DateTime startDate = firstOfMonth.AddDays(-(int)firstOfMonth.DayOfWeek);
            // Build a table containing 6 rows (weeks) x 7 columns (day of week)
            StringBuilder month = new StringBuilder();
            StringBuilder html  = new StringBuilder();

            for (int i = 0; i < 42; i++)
            {
                // Get the date to display
                DateTime displayDate = startDate.AddDays(i);
                // Determine if the date is selectable
                bool canSelect = true;
                if (displayDate.Month != date.Month)
                {
                    canSelect = false;
                }
                else if (minDate.HasValue && displayDate < minDate.Value)
                {
                    canSelect = false;
                }
                else if (maxDate.HasValue && displayDate > maxDate.Value)
                {
                    canSelect = false;
                }
                html.Append(Day(displayDate, isSelected && date == displayDate, canSelect));
                if (i % 7 == 6)
                {
                    // Its the end of the week, so start a new row in the table
                    System.Web.Mvc.TagBuilder week = new System.Web.Mvc.TagBuilder("tr");
                    week.InnerHtml = html.ToString();
                    month.Append(week.ToString());
                    html.Clear();
                }
            }
            // Construct the table body
            System.Web.Mvc.TagBuilder calendar = new System.Web.Mvc.TagBuilder("tbody");
            calendar.AddCssClass("calendar-dates");
            calendar.InnerHtml = month.ToString();
            // Return the html
            return(calendar.ToString());
        }
Exemplo n.º 13
0
 /// <summary>
 /// Returns the html for the date picker input, including validation attributes and message.
 /// </summary>
 /// <param name="helper">
 /// The html helper.
 /// </param>
 /// <param name="metadata">
 /// The meta data of the property to display the date for.
 /// </param>
 /// <param name="name">
 /// The fully qualified name of the property.
 /// </param>
 /// <returns></returns>
 private static string DatePickerInput(System.Web.Mvc.HtmlHelper helper, System.Web.Mvc.ModelMetadata metadata, string name)
 {
     // Construct the input
     System.Web.Mvc.TagBuilder input = new System.Web.Mvc.TagBuilder("input");
     input.AddCssClass("datepicker-input");
     input.MergeAttribute("type", "text");
     input.MergeAttribute("id", System.Web.Mvc.HtmlHelper.GenerateIdFromName(name));
     input.MergeAttribute("autocomplete", "off");
     input.MergeAttribute("name", name);
     input.MergeAttributes(helper.GetUnobtrusiveValidationAttributes(name, metadata));
     if (metadata.Model != null)
     {
         input.MergeAttribute("value", ((DateTime)metadata.Model).ToShortDateString());
     }
     // Return the html
     return(input.ToString());
 }
Exemplo n.º 14
0
        public static MvcHtmlString MarkedAuthors(this HtmlHelper helper, List <Author> authors, string search)
        {
            string result = "";

            for (int i = 0; i < authors.Count; i++)
            {
                TagBuilder a = new System.Web.Mvc.TagBuilder("a");
                a.Attributes["href"] = "#";
                a.InnerHtml          = authors[i].Name;
                result += a.ToString();
                if (i > 0)
                {
                    result += ", ";
                }
            }
            return(MvcHtmlString.Create(result));
        }
Exemplo n.º 15
0
        public static IHtmlString GoogleCaptcha(this HtmlHelper helper)
        {
            var publicSiteKey = ConfigurationManager.AppSettings["GoogleRecaptchaSiteKey"];

            var mvcHtmlString = new System.Web.Mvc.TagBuilder("div")
            {
                Attributes =
                {
                    new KeyValuePair <string, string>("class",        "g-recaptcha"),
                    new KeyValuePair <string, string>("data-sitekey", publicSiteKey)
                }
            };

            const string googleCaptchaScript = "<script src='https://www.google.com/recaptcha/api.js'></script>";
            var          renderedCaptcha     = mvcHtmlString.ToString(TagRenderMode.Normal);

            return(MvcHtmlString.Create($"{googleCaptchaScript}{renderedCaptcha}"));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Returns the html for a table row displaying the days of the week.
        /// </summary>
        private static string WeekHeader()
        {
            // Build a table cell for each day of the week
            string[]      daysOfWeek = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
            StringBuilder html       = new StringBuilder();

            for (int i = 0; i < 7; i++)
            {
                System.Web.Mvc.TagBuilder day = new System.Web.Mvc.TagBuilder("td");
                day.InnerHtml = daysOfWeek[i];
                html.Append(day.ToString());
            }
            // Construct the table row
            System.Web.Mvc.TagBuilder week = new System.Web.Mvc.TagBuilder("tr");
            week.AddCssClass("calendar-daysOfWeek");
            week.InnerHtml = html.ToString();
            // Return the html
            return(week.ToString());
        }
Exemplo n.º 17
0
        public static MvcHtmlString SideBarSecureActionLink(this HtmlHelper htmlHelper, string linkText, string url, string cssClass, string spanCssClass, params string[] permission)
        {
            var hasPermission = permission.Any(HttpContext.Current.User.IsInRole);

            if (!hasPermission)
            {
                return(MvcHtmlString.Empty);
            }

            var a = new TagBuilder("a");

            a.Attributes.Add("href", url);
            a.AddCssClass(cssClass);
            var span = new TagBuilder("span");

            span.AddCssClass(spanCssClass);
            a.InnerHtml = span.ToString(TagRenderMode.Normal) + linkText;

            return(MvcHtmlString.Create(a.ToString()));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Writes an opening <![CDATA[ <a> ]]> tag to the response if the shouldWriteLink argument is true.
        /// Returns a ConditionalLink object which when disposed will write a closing <![CDATA[ </a> ]]> tag
        /// to the response if the shouldWriteLink argument is true.
        /// </summary>
        public static ConditionalLink BeginConditionalLink(this HtmlHelper helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null)
        {
            if (shouldWriteLink)
            {
                var linkTag = new System.Web.Mvc.TagBuilder("a");
                linkTag.Attributes.Add("href", url.ToHtmlString());

                if (!string.IsNullOrWhiteSpace(title))
                {
                    linkTag.Attributes.Add("title", helper.Encode(title));
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    linkTag.Attributes.Add("class", cssClass);
                }

                helper.ViewContext.Writer.Write(linkTag.ToString(TagRenderMode.StartTag));
            }
            return new ConditionalLink(helper.ViewContext, shouldWriteLink);
        }
        //public static IHtmlContent GetList(this IHtmlHelper helper)
        // {

        //   System.Web.Mvc.TagBuilder li = new System.Web.Mvc.TagBuilder("li");


        //     var listHtml = new HtmlContentBuilder();
        //     listHtml.AppendHtml("<li class='dropdown'>");
        //     listHtml.AppendHtml("<a class='fa fa - user' data-toggle='dropdown'");
        //     listHtml.AppendHtml("<span class='caret'>");
        //     listHtml.AppendHtml("</span>");
        //     listHtml.AppendHtml("</a>");
        //     listHtml.AppendHtml("<ul class='dropdown-menu'>");
        //     listHtml.AppendHtml("<li>");
        //     listHtml.AppendHtml("<a>");
        //     listHtml.AppendHtml(helper.ActionLink("foo", "bar", "example"));
        //     listHtml.AppendHtml("</a>");
        //     listHtml.AppendHtml("</li>");
        //     listHtml.AppendHtml("</ul>");
        //     listHtml.AppendHtml("</li>");

        //     return listHtml;
        // }

        /*public static IHtmlContent GenerateInput(this IHtmlHelper<TModel> helper)
         * {
         *  var tb = new TagBuilder("input");
         *
         *  tb.TagRenderMode = TagRenderMode.SelfClosing;
         *  tb.MergeAttribute("name", this.GetIdentity());
         *  tb.MergeAttribute("type", "hidden");
         *  tb.MergeAttribute("value", this.GetSelectedItem()?.Value);
         *  return tb;
         * }*/

        //           <div class="form-group">
        //    <label class="col-sm-2 control-label"><span class="input-group-text" id="inputGroup-sizing-default">@Html.LabelFor(x => x.Name)</span></label>
        //    <div class="col-sm-10">
        //        @Html.TextBoxFor(x => x.Name, new { @class = "form-control" })
        //        <span asp-validation-for="Name" />
        //    </div>
        //</div>


        public static IHtmlContent LabeledTextBoxFor <TModel, TResult>(this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TResult> > expression)
        {
            var builder = new System.Web.Mvc.TagBuilder("div");

            builder.AddCssClass("form-group");

            var label = new System.Web.Mvc.TagBuilder("label");

            label.AddCssClass("col-sm-2 control-label");
            label.Attributes.Add("id", "");

            //  builder.InnerHtml += label.toHtml

            var textBoxFor = htmlHelper.TextBoxFor(expression);
            var labelFor   = htmlHelper.LabelFor(expression);

            builder.InnerHtml = "polof";


            return(new HtmlString(builder.ToString()));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Writes an opening <![CDATA[ <a> ]]> tag to the response if the shouldWriteLink argument is true.
        /// Returns a ConditionalLink object which when disposed will write a closing <![CDATA[ </a> ]]> tag
        /// to the response if the shouldWriteLink argument is true.
        /// </summary>
        public static ConditionalLink BeginConditionalLink(this HtmlHelper helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null)
        {
            if (shouldWriteLink)
            {
                var linkTag = new System.Web.Mvc.TagBuilder("a");
                linkTag.Attributes.Add("href", url.ToHtmlString());

                if (!string.IsNullOrWhiteSpace(title))
                {
                    linkTag.Attributes.Add("title", helper.Encode(title));
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    linkTag.Attributes.Add("class", cssClass);
                }

                helper.ViewContext.Writer.Write(linkTag.ToString(TagRenderMode.StartTag));
            }
            return(new ConditionalLink(helper.ViewContext, shouldWriteLink));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Return the html for a calendar.
        /// </summary>
        /// <param name="date">
        /// A date in the month to display.
        /// </param>
        /// <param name="isSelected">
        /// A value indicating if the date should be marked as selected.
        /// </param>
        /// <param name="minDate">
        /// The minimum date that can be selected.
        /// </param>
        /// <param name="maxDate">
        /// The maximum date that can be selected.
        /// </param>
        private static string Calendar(DateTime date, bool isSelected, DateTime?minDate, DateTime?maxDate)
        {
            StringBuilder html = new StringBuilder();

            // Add header
            html.Append(CalendarHeader(date, minDate, maxDate));
            // Add body
            html.Append(Month(date, isSelected, minDate, maxDate));
            // Construct table
            System.Web.Mvc.TagBuilder table = new System.Web.Mvc.TagBuilder("table");
            table.InnerHtml = html.ToString();
            // Construct inner container that can optionally be styled as position:absolute if within a date picker
            System.Web.Mvc.TagBuilder inner = new System.Web.Mvc.TagBuilder("div");
            inner.AddCssClass("container");
            inner.InnerHtml = table.ToString();
            // Construct outer container
            System.Web.Mvc.TagBuilder outer = new System.Web.Mvc.TagBuilder("div");
            outer.AddCssClass("calendar");
            outer.InnerHtml = inner.ToString();
            // Return the html
            return(outer.ToString());
        }
Exemplo n.º 22
0
        public static MvcHtmlString ButtonAlert(this HtmlHelper helper, string text, string title, Action modal, string action, object htmlAttributes = null, object iconAttributes = null, string value = null, bool disabled = false)
        {
            TagBuilder _ibuilder   = null;
            TagBuilder _builder    = new TagBuilder("a");
            TagBuilder _pbuilder   = new TagBuilder("span");
            UrlHelper  _urlHelper  = new UrlHelper(helper.ViewContext.RequestContext);
            string     _controller = Extensions.NullToString(helper.ViewContext.RouteData.GetRequiredString("controller"));

            _builder.GenerateId("btn" + (string.IsNullOrEmpty(text) ? title : text));
            _builder.Attributes["title"]       = title;
            _builder.Attributes["data-widget"] = modal.GetValueAsString();
            _builder.Attributes["href"]        = "#";
            _builder.Attributes["data-href"]   = (action != null ? _urlHelper.Action(action, _controller) : "#");

            if (disabled)
            {
                _builder.Attributes["disabled"] = "disabled";
            }

            if (iconAttributes != null)
            {
                _ibuilder = new TagBuilder("i");
                _ibuilder.MergeAttributes(new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(iconAttributes)));
                _builder.InnerHtml = string.Format("{0}{1}", _builder.InnerHtml, _ibuilder.ToString());
            }

            if (value != null)
            {
                _pbuilder.InnerHtml = value;
                _pbuilder.MergeAttributes(new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
            }
            else
            {
                _pbuilder.InnerHtml = text;
            }
            _builder.InnerHtml = string.Format("{0} {1}", _builder.InnerHtml, _pbuilder.ToString());
            return(MvcHtmlString.Create(_builder.ToString()));
        }
Exemplo n.º 23
0
        public static IHtmlString RecaptchaInvisible(this HtmlHelper helper, string text, object htmlAttributes = null)
        {
            var attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            if (helper.ViewContext.Controller is OnWeb.Core.Modules.ModuleControllerBase controller)
            {
                var appCore = controller.AppCore;
                if (appCore != null)
                {
                    var module = appCore.Get <OnWeb.Modules.reCAPTCHA.ModuleReCaptcha>();
                    var cfg    = module?.GetConfiguration <OnWeb.Modules.reCAPTCHA.ModuleReCaptchaConfiguration>();
                    if (cfg != null && cfg.IsEnabledValidation && !string.IsNullOrEmpty(cfg.PublicKey))
                    {
                        var tagBuilder = new TagBuilder("button");
                        foreach (var attr in attrs)
                        {
                            tagBuilder.MergeAttribute(attr.Key, attr.Value.ToString());
                        }
                        tagBuilder.SetInnerText(text);
                        tagBuilder.AddCssClass("captchaInvisible");
                        tagBuilder.MergeAttribute("data-sitekey", cfg.PublicKey);

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

            var tagBuilder2 = new TagBuilder("input");

            foreach (var attr in attrs)
            {
                tagBuilder2.MergeAttribute(attr.Key, attr.Value.ToString());
            }
            tagBuilder2.MergeAttribute("value", text);
            tagBuilder2.MergeAttribute("type", "submit");

            return(new MvcHtmlString(tagBuilder2.ToString(TagRenderMode.Normal)));
        }
        private static TagBuilder AddValidationMessages(HtmlHelper htmlHelper, IEnumerable <ModelState> values)
        {
            StringBuilder builder2 = new StringBuilder();
            TagBuilder    builder3 = new TagBuilder("ul");

            if (values != null)
            {
                foreach (var msg in values.SelectMany(v => v.Errors.Select(e => GetUserErrorMessageOrDefault(htmlHelper.ViewContext.HttpContext, e, null))
                                                      .Where(m => !string.IsNullOrEmpty(m)))
                         .Distinct())
                {
                    TagBuilder builder4 = new TagBuilder("li");
                    builder4.SetInnerText(msg);
                    builder2.AppendLine(builder4.ToString(TagRenderMode.Normal));
                }
            }
            if (builder2.Length == 0)
            {
                builder2.AppendLine("<li style=\"display:none\"></li>");
            }
            builder3.InnerHtml = builder2.ToString();
            return(builder3);
        }
        public static IHtmlContent File <TModel, TResult>(this IHtmlHelper <IModel> htmlHelper, Expression <Func <TModel, TResult> > expression, string id)
        {
            var div = new System.Web.Mvc.TagBuilder("div");

            div.AddCssClass("form-control");

            var label = new System.Web.Mvc.TagBuilder("label");

            label.AddCssClass("col-sm-2 control-label");

            var span = new System.Web.Mvc.TagBuilder("span");

            span.AddCssClass("input-group-text");
            span.Attributes.Add("id", "inputGroup-sizing-default");

            // var textBoxFor = htmlHelper.TextBoxFor(expression);
            // var labelFor = htmlHelper.LabelFor(expression);

            System.Web.Mvc.TagBuilder tb = new System.Web.Mvc.TagBuilder("input");
            tb.Attributes.Add("type", "file");
            tb.Attributes.Add("id", id);
            return(new HtmlString(tb.ToString()));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Returns the html for the table header row displaying the current month and navigation buttons.
        /// </summary>
        /// <param name="date">
        /// A date in the month to display.
        /// </param>
        /// <param name="minDate">
        /// The minimum date that can be selected.
        /// </param>
        /// <param name="maxDate">
        /// The maximmum date that can be selected.
        /// </param>
        private static string MonthHeader(DateTime date, DateTime?minDate, DateTime?maxDate)
        {
            StringBuilder html = new StringBuilder();
            // Add previous month navigation button
            bool hidePrevious = minDate.HasValue && date.FirstOfMonth() <= minDate.Value;

            html.Append(NavigationButton("previousButton", hidePrevious));
            // Add month label
            System.Web.Mvc.TagBuilder label = new System.Web.Mvc.TagBuilder("span");
            label.InnerHtml = string.Format("{0:MMMM yyyy}", date);
            System.Web.Mvc.TagBuilder cell = new System.Web.Mvc.TagBuilder("th");
            cell.MergeAttribute("colspan", "5");
            cell.InnerHtml = label.ToString();
            html.Append(cell);
            // Add next month navigation button
            bool hideNext = maxDate.HasValue && date.LastOfMonth() >= maxDate.Value;

            html.Append(NavigationButton("nextButton", hideNext));
            // Construct header row
            System.Web.Mvc.TagBuilder header = new System.Web.Mvc.TagBuilder("tr");
            header.InnerHtml = html.ToString();
            // Return the html
            return(header.ToString());
        }
Exemplo n.º 27
0
        public static MvcHtmlString Button(this HtmlHelper helper, string text, string title, Action modal, object htmlAttributes = null, object iconAttributes = null, bool disabled = false)
        {
            TagBuilder _ibuilder  = null;
            TagBuilder _builder   = new TagBuilder("a");
            TagBuilder _pbuilder  = new TagBuilder("span");
            UrlHelper  _urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

            _builder.GenerateId("btn" + (string.IsNullOrEmpty(title) ? text : title));
            _builder.Attributes["title"] = title;
            _builder.Attributes["href"]  = "#";

            if (modal.Equals(Action.Dismiss))
            {
                _builder.Attributes["data-dismiss"] = modal.GetValueAsString();
            }
            else
            {
                _builder.Attributes["data-widget"] = modal.GetValueAsString();
            }

            if (disabled)
            {
                _builder.Attributes["disabled"] = "disabled";
            }

            if (iconAttributes != null)
            {
                _ibuilder = new TagBuilder("i");
                _ibuilder.MergeAttributes(new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(iconAttributes)));
                _builder.InnerHtml = string.Format("{0}{1}", _builder.InnerHtml, _ibuilder.ToString());
            }
            _pbuilder.InnerHtml = text;
            _builder.InnerHtml  = string.Format("{0} {1}", _builder.InnerHtml, _pbuilder.ToString());
            _builder.MergeAttributes(new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
            return(MvcHtmlString.Create(_builder.ToString()));
        }
        /// <summary>
        /// Validations the summary.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="groupName">Name of the group.</param>
        /// <param name="excludePropertyErrors">if set to <c>true</c> [exclude property errors].</param>
        /// <param name="message">The message.</param>
        /// <param name="htmlAttributes">The HTML attributes.</param>
        /// <returns></returns>
        public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string groupName, bool excludePropertyErrors, string message, IDictionary <string, object> htmlAttributes)
        {
            #region Validate Arguments
            if (htmlHelper == null)
            {
                throw new ArgumentNullException("htmlHelper");
            }
            groupName = groupName ?? string.Empty;
            #endregion

            string[] groupNames = groupName.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

            if (htmlAttributes == null)
            {
                htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(null);
            }
            htmlAttributes["data-val-valgroup-name"] = groupName;



            object model = htmlHelper.ViewData.Model;
            ModelStateDictionary modelState = htmlHelper.ViewData.ModelState;

            bool canValidate = !modelState.ContainsKey(ValidationGroupsKey) ||
                               (groupNames.Any() && ((IEnumerable <string>)modelState[ValidationGroupsKey].Value.RawValue).Intersect(groupNames).Any()) ||
                               (!groupNames.Any());
            IEnumerable <ModelState> faulted           = canValidate ? GetFaultedModelStates(htmlHelper, groupNames, model) : Enumerable.Empty <ModelState>();
            FormContext formContextForClientValidation = htmlHelper.ViewContext.ClientValidationEnabled ? htmlHelper.ViewContext.FormContext : null;
            if (!canValidate || !faulted.Any())
            {
                if (formContextForClientValidation == null)
                {
                    return(null);
                }
            }
            string str = InitializeResponseString(message);

            IEnumerable <ModelState> values = GetValues(htmlHelper, excludePropertyErrors, modelState, faulted);
            TagBuilder builder3             = AddValidationMessages(htmlHelper, values);
            TagBuilder tagBuilder           = new TagBuilder("div");
            tagBuilder.MergeAttributes <string, object>(htmlAttributes);
            tagBuilder.AddCssClass("validation-summary");
            tagBuilder.AddCssClass(!faulted.Any() ? HtmlHelper.ValidationSummaryValidCssClassName : HtmlHelper.ValidationSummaryCssClassName);
            tagBuilder.InnerHtml = str + builder3.ToString(TagRenderMode.Normal);
            if (formContextForClientValidation != null)
            {
                if (htmlHelper.ViewContext.UnobtrusiveJavaScriptEnabled)
                {
                    if (!excludePropertyErrors)
                    {
                        tagBuilder.MergeAttribute("data-valmsg-summary", "true");
                    }
                }
                else
                {
                    tagBuilder.GenerateId("validationSummary");
                    formContextForClientValidation.ValidationSummaryId      = tagBuilder.Attributes["id"];
                    formContextForClientValidation.ReplaceValidationSummary = !excludePropertyErrors;
                }
            }
            return(new MvcHtmlString(tagBuilder.ToString(TagRenderMode.Normal)));
        }
Exemplo n.º 29
0
        private static MvcHtmlString BootstrapInputHelper(HtmlHelper htmlHelper, InputType inputType, ModelMetadata metadata, string name, object value, bool useViewData, bool isChecked, bool setId, bool isExplicitValue, IDictionary <string, object> htmlAttributes, string blockHelpText)
        {
            string fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            if (String.IsNullOrEmpty(fullName))
            {
                throw new ArgumentException("Value cannot be null or empty.", "name");
            }

            TagBuilder tagBuilder = new TagBuilder("input");

            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("type", HtmlHelper.GetInputTypeString(inputType));
            tagBuilder.MergeAttribute("name", fullName, true);

            string valueParameter = Convert.ToString(value, CultureInfo.CurrentCulture);
            bool   usedModelState = false;

            switch (inputType)
            {
            case InputType.CheckBox:
                bool?modelStateWasChecked = htmlHelper.GetModelStateValue(fullName, typeof(bool)) as bool?;
                if (modelStateWasChecked.HasValue)
                {
                    isChecked      = modelStateWasChecked.Value;
                    usedModelState = true;
                }
                goto case InputType.Radio;

            case InputType.Radio:
                if (!usedModelState)
                {
                    string modelStateValue = htmlHelper.GetModelStateValue(fullName, typeof(string)) as string;
                    if (modelStateValue != null)
                    {
                        isChecked      = String.Equals(modelStateValue, valueParameter, StringComparison.Ordinal);
                        usedModelState = true;
                    }
                }
                if (!usedModelState && useViewData)
                {
                    isChecked = htmlHelper.EvalBoolean(fullName);
                }
                if (isChecked)
                {
                    tagBuilder.MergeAttribute("checked", "checked");
                }
                tagBuilder.MergeAttribute("value", valueParameter, isExplicitValue);
                break;

            case InputType.Password:
                if (value != null)
                {
                    tagBuilder.MergeAttribute("value", valueParameter, isExplicitValue);
                }
                break;

            default:
                string attemptedValue = (string)htmlHelper.GetModelStateValue(fullName, typeof(string));
                tagBuilder.MergeAttribute("value", attemptedValue ?? ((useViewData) ? htmlHelper.EvalString(fullName) : valueParameter), isExplicitValue);
                break;
            }

            if (setId)
            {
                tagBuilder.GenerateId(fullName);
            }

            // If there are any errors for a named field, we add the css attribute.
            ModelState modelState;

            if (htmlHelper.ViewData.ModelState.TryGetValue(fullName, out modelState))
            {
                if (modelState.Errors.Count > 0)
                {
                    tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
                }
            }

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

            if (inputType == InputType.CheckBox)
            {
                // Render an additional <input type="hidden".../> for checkboxes. This
                // addresses scenarios where unchecked checkboxes are not sent in the request.
                // Sending a hidden input makes it possible to know that the checkbox was present
                // on the page when the request was submitted.
                StringBuilder inputItemBuilder = new StringBuilder();
                inputItemBuilder.Append(tagBuilder.ToString(TagRenderMode.SelfClosing));

                TagBuilder hiddenInput = new TagBuilder("input");
                hiddenInput.MergeAttribute("type", HtmlHelper.GetInputTypeString(InputType.Hidden));
                hiddenInput.MergeAttribute("name", fullName);
                hiddenInput.MergeAttribute("value", "false");
                inputItemBuilder.Append(hiddenInput.ToString(TagRenderMode.SelfClosing));
                return(MvcHtmlString.Create(inputItemBuilder.ToString()));
            }
            else if (!String.IsNullOrEmpty(blockHelpText))
            {
                // Render an additional <span class="help-block"> inside
                // the <input ...> for the help text
                StringBuilder inputItemBuilder = new StringBuilder();
                inputItemBuilder.Append(tagBuilder.ToString(TagRenderMode.StartTag));

                TagBuilder span = new TagBuilder("span");
                span.MergeAttribute("class", "help-block");
                inputItemBuilder.Append(span.ToString(TagRenderMode.StartTag));
                inputItemBuilder.Append(blockHelpText);
                inputItemBuilder.Append(span.ToString(TagRenderMode.EndTag));
                inputItemBuilder.Append(tagBuilder.ToString(TagRenderMode.EndTag));

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

            return(new MvcHtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing)));
        }
Exemplo n.º 30
0
        /// <summary>
        /// 上图分页右边的 页数信息
        /// </summary>
        /// <param name="html"></param>
        /// <param name="pagingInfo"></param>
        /// <param name="pageUrl"></param>
        /// <returns></returns>
        public static MvcHtmlString PageLinks(this System.Web.Mvc.HtmlHelper html, PagingInfo pagingInfo, Func <int, string> pageUrl)
        {
            //新建StringBuilder实例result       将他作为最终的html字符串生成相应的标签
            StringBuilder result = new StringBuilder();

            if (pagingInfo.TotalPages != 0)
            {
                //首页 前页
                TagBuilder tagPrior = new TagBuilder("a");
                tagPrior.InnerHtml = "上一页";
                //将标签tostring后 追加到StringBuilder
                if (pagingInfo.CurrentPage != 1)
                {
                    tagPrior.MergeAttribute("href", pageUrl(pagingInfo.CurrentPage - 1));
                }
                else
                {
                    tagPrior.MergeAttribute("class", "prev-disabled");
                }
                result.Append(tagPrior.ToString());


                //1
                if (pagingInfo.TotalPages >= 1)
                {
                    TagBuilder one = new TagBuilder("a");
                    one.InnerHtml = "1";
                    one.MergeAttribute("href", pageUrl(1));
                    if (pagingInfo.CurrentPage == 1)
                    {
                        one.MergeAttribute("class", "current");
                    }
                    result.Append(one.ToString());
                }

                //2
                if (pagingInfo.TotalPages >= 2)
                {
                    TagBuilder two = new TagBuilder("a");
                    two.InnerHtml = "2";
                    two.MergeAttribute("href", pageUrl(2));
                    if (pagingInfo.CurrentPage == 2)
                    {
                        two.MergeAttribute("class", "current");
                    }
                    result.Append(two.ToString());
                }


                if (pagingInfo.CurrentPage > 5 && pagingInfo.TotalPages != 6)
                {
                    TagBuilder span = new TagBuilder("span");
                    span.InnerHtml = "...";
                    span.MergeAttribute("class", "text");
                    result.Append(span.ToString());
                }

                int index = pagingInfo.CurrentPage > 2 ?
                            pagingInfo.CurrentPage :
                            3;

                //1,2,3,4,5的时候
                if (pagingInfo.CurrentPage <= 5)
                {
                    int start = 3;
                    for (int i = start; i < 8 && i <= pagingInfo.TotalPages; i++)
                    {
                        TagBuilder temp = new TagBuilder("a");
                        temp.InnerHtml = i.ToString();
                        temp.MergeAttribute("href", pageUrl(i));
                        if (i == pagingInfo.CurrentPage)
                        {
                            temp.MergeAttribute("class", "current");
                        }
                        result.Append(temp.ToString());
                    }

                    if (pagingInfo.TotalPages > 7)
                    {
                        TagBuilder span = new TagBuilder("span");
                        span.InnerHtml = "...";
                        span.MergeAttribute("class", "text");
                        result.Append(span.ToString());
                    }
                }

                //后面不足5个
                if (pagingInfo.CurrentPage > 5 && pagingInfo.CurrentPage + 5 > pagingInfo.TotalPages)
                {
                    int start = pagingInfo.TotalPages - 4;
                    if (start == 2)
                    {
                        start += 1;
                    }
                    for (int i = start; i <= pagingInfo.TotalPages; i++)
                    {
                        TagBuilder temp = new TagBuilder("a");
                        temp.InnerHtml = i.ToString();
                        temp.MergeAttribute("href", pageUrl(i));
                        if (i == pagingInfo.CurrentPage)
                        {
                            temp.MergeAttribute("class", "current");
                        }
                        result.Append(temp.ToString());
                    }
                }

                //大于5的时候
                if (pagingInfo.CurrentPage > 5 && pagingInfo.CurrentPage + 5 <= pagingInfo.TotalPages)
                {
                    //index = pagingInfo.CurrentPage % 5;
                    for (int i = pagingInfo.CurrentPage; i < pagingInfo.CurrentPage + 5; i++)
                    {
                        TagBuilder temp = new TagBuilder("a");
                        temp.InnerHtml = (i - 2).ToString();
                        temp.MergeAttribute("href", pageUrl(i - 2));
                        if (i == pagingInfo.CurrentPage + 2)
                        {
                            temp.MergeAttribute("class", "current");
                        }
                        result.Append(temp.ToString());
                    }
                    TagBuilder span = new TagBuilder("span");
                    span.InnerHtml = "...";
                    span.MergeAttribute("class", "text");
                    result.Append(span.ToString());
                }


                //下一页
                TagBuilder tagAfter = new TagBuilder("a");
                tagAfter.InnerHtml = "下一页";
                if (pagingInfo.CurrentPage != pagingInfo.TotalPages)
                {
                    tagAfter.MergeAttribute("href", pageUrl(pagingInfo.CurrentPage + 1));
                }
                else
                {
                    tagAfter.MergeAttribute("class", "next-disabled");
                }
                result.Append(tagAfter.ToString());
            }

            //创建html标签 返回!!!
            return(MvcHtmlString.Create(result.ToString()));
        }
Exemplo n.º 31
0
        public static MvcHtmlString Button(this HtmlHelper helper, string text, string title, Action modal, string action, object route = null, object htmlAttributes = null, object iconAttributes = null, bool disabled = false)
        {
            TagBuilder _builder    = new TagBuilder("a");
            TagBuilder _pbuilder   = new TagBuilder("span");
            UrlHelper  _urlHelper  = new UrlHelper(helper.ViewContext.RequestContext);
            string     _controller = Extensions.NullToString(helper.ViewContext.RouteData.GetRequiredString("controller"));

            _builder.GenerateId("btn" + (string.IsNullOrEmpty(text) ? title : text));
            _builder.Attributes["title"] = title;

            if (modal.Equals(Action.Dismiss))
            {
                _builder.Attributes["data-dismiss"] = modal.GetValueAsString();
            }
            else
            {
                _builder.Attributes["data-widget"] = modal.GetValueAsString();
            }
            _builder.Attributes["href"]      = "#";
            _builder.Attributes["data-href"] = (action != null ? _urlHelper.Action(action, _controller, route) : "#");

            if (disabled)
            {
                _builder.Attributes["disabled"] = "disabled";
            }

            if (iconAttributes != null)
            {
                TagBuilder ibuilder = new TagBuilder("i");
                ibuilder.MergeAttributes(new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(iconAttributes)));
                _builder.InnerHtml = string.Format("{0}{1}", _builder.InnerHtml, ibuilder.ToString());
            }
            _pbuilder.InnerHtml = text;
            _builder.InnerHtml  = string.Format("{0} {1}", _builder.InnerHtml, _pbuilder.ToString());

            if (modal.Equals(Action.Upload))
            {
                TagBuilder xbuilder = new TagBuilder("input");
                xbuilder.Attributes["id"]      = "getfile";
                xbuilder.Attributes["name"]    = "getfile";
                xbuilder.Attributes["type"]    = "file";
                xbuilder.Attributes["enctype"] = "multipart/form-data";
                _builder.InnerHtml             = string.Format("{0} {1}", _builder.InnerHtml, xbuilder.ToString());
            }
            _builder.MergeAttributes(new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
            return(MvcHtmlString.Create(_builder.ToString()));
        }
 internal static MvcHtmlString ToMvcHtmlString(this TagBuilder tagBuilder, TagRenderMode renderMode)
 {
     Debug.Assert(tagBuilder != null);
     return(new MvcHtmlString(tagBuilder.ToString(renderMode)));
 }
Exemplo n.º 33
0
        /// <summary>
        /// 自动补全 模糊查询会员和商品
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="id">文本id名称</param>
        /// <param name="HiddenId">隐藏文本id名 用于存放选中的id号</param>
        /// <param name="Type">查询类型 1会员 2商品</param>
        /// <param name="value">初始化绑定值</param>
        /// <param name="HiddenValue">初始化绑定隐藏文本的值</param>
        /// <param name="classStr">文本的clss样式</param>
        /// <returns>2017-8-21 吴琨 创建 </returns>
        public static MvcHtmlString UtilLike(this HtmlHelper helper, string id, string HiddenId, int Type, string value, int HiddenValue, string classStr)
        {
            var htmlStr = new StringBuilder();

            htmlStr.Append("<input type=\"text\" value=\"" + value + "\" id=\"" + id + "\" name=\"" + id + "\" class=\"" + classStr + "\"  oninput=\"fn_" + id + "()\" onpropertychange=\"fn_" + id + "()\"  onblur=\"blur_" + id + "(this,'" + Type + "')\"   style=\" width:176px;\" />");
            htmlStr.Append("<input type=\"hidden\" id=\"" + HiddenId + "\" name=\"" + HiddenId + "\" value=\"" + HiddenValue + "\" />");
            #region 会员
            if (Type == 1)
            {
                htmlStr.Append("\r\n");
                htmlStr.Append("<button id=\"search_customer\" class=\"btn btn_ht26\" title=\"搜索\" type=\"button\" onclick=\"popUserInfo(this)\">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<div class=\"icon_search\"></div>");
                htmlStr.Append("\r\n");
                htmlStr.Append("</button>");
                htmlStr.Append("\r\n");
                #region html文本
                htmlStr.Append("<div id=\"div_" + id + "\" style=\"width: 420px; overflow-y: scroll; height: 240px; z-index: 100; background-color: #ffffff; position: absolute; border: #e1e1e1 solid 1px; text-align: center; display:none;   \">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"width: 100%;\">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<tr style=\"background: url(/Theme/images/boxbg.png) repeat-x 0 -40px; line-height: 34px; \">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>账号</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>姓名</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>手机</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>会员ID</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("</tr>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<tbody>");
                htmlStr.Append("</tbody>");
                htmlStr.Append("\r\n");
                htmlStr.Append("</table>\r\n</div>");
                htmlStr.Append("\r\n");
                #endregion
            }
            #endregion

            #region 商品
            else
            {
                #region html文本
                htmlStr.Append("<div id=\"div_" + id + "\" style=\"width: 420px; overflow-y: scroll; height: 240px; z-index: 100; background-color: #ffffff; position: absolute; border: #e1e1e1 solid 1px; text-align: center; display:none;   \">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"width: 100%;\">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<tr style=\"background: url(/Theme/images/boxbg.png) repeat-x 0 -40px; line-height: 34px; \">");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>编号</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>条码</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>后台名称</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<th>商品ID</th>");
                htmlStr.Append("\r\n");
                htmlStr.Append("</tr>");
                htmlStr.Append("\r\n");
                htmlStr.Append("<tbody>");
                htmlStr.Append("</tbody>");
                htmlStr.Append("\r\n");
                htmlStr.Append("</table>\r\n</div>");
                htmlStr.Append("\r\n");
                #endregion
            }
            #endregion

            #region js事件
            var tag = new TagBuilder("script");
            tag.MergeAttribute("type", "text/javascript");
            //文本改变启动
            tag.InnerHtml += "\r\n";
            tag.InnerHtml += "var timer = true;";
            tag.InnerHtml += "function fn_" + id + "()";
            tag.InnerHtml += "{";
            tag.InnerHtml += "\r\n";
            tag.InnerHtml += " $(\"#div_" + id + "\").show();  ";
            htmlStr.Append("\r\n");
            tag.InnerHtml += "if(timer&&$(\"#" + id + "\").val().length>0){ timer=false; ";
            tag.InnerHtml += "setTimeout(function(){ timer=true; var val=$(\"#" + id + "\").val();  GetUtilLike(val," + Type + ",'div_" + id + "'); },1000)";
            tag.InnerHtml += "}";
            tag.InnerHtml += "\r\n";
            tag.InnerHtml += "}";
            tag.InnerHtml += "\r\n";
            //失去焦点启动
            tag.InnerHtml += "function blur_" + id + "(th,type)";
            tag.InnerHtml += "{";
            tag.InnerHtml += "\r\n";
            tag.InnerHtml += "setTimeout(function(){ $(\"#div_" + id + "\").hide(); inspect(th,type); },500)";
            tag.InnerHtml += "\r\n";
            tag.InnerHtml += "}";
            #endregion
            return(MvcHtmlString.Create(htmlStr.ToString() + tag.ToString(TagRenderMode.Normal)));
        }