internal static MvcHtmlString DateTimeForInternal <TModel>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, BsDateTime> > expression,
                                                                   IDictionary <string, object> htmlAttributes, IDictionary <string, object> dataOptions)
        {
            var inputHtml = new StringBuilder();
            var name      = ExpressionHelper.GetExpressionText(expression);
            var fullName  = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
            var bsDate    = expression.Compile().Invoke(htmlHelper.ViewData.Model);

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

            if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState))
            {
                if (modelState.Errors.Count > 0)
                {
                    htmlAttributes.MergeAttribute("class", HtmlHelper.ValidationInputCssClassName);
                }
            }

            //Validation Hack
            name = name.Replace(".TextValue", "");

            var attributes = htmlHelper.GetUnobtrusiveValidationAttributes(name);

            if (name.Contains(".") && !attributes.Any())
            {
                attributes = htmlHelper.GetUnobtrusiveValidationAttributes(name.Split('.').LastOrDefault());
            }

            foreach (var item in attributes)
            {
                htmlAttributes.MergeAttribute(item.Key, item.Value.ToString(), true);
            }

            //Set display value
            string displayValue = null;

            if (bsDate != null && !string.IsNullOrEmpty(bsDate.TextValue))
            {
                displayValue = bsDate.TextValue;
            }

            //render input type text
            inputHtml.Append(htmlHelper.TextBox(name + ".TextValue", displayValue, htmlAttributes).ToHtmlString());

            //render hidden for range
            htmlAttributes = new Dictionary <string, object>();
            htmlAttributes.MergeAttribute("data-for", fullName + ".TextValue");

            //From
            var fromName = fullName + ".DateValue";

            htmlAttributes.MergeAttribute("class", "bs-date-iso", true);

            var valFormated = (bsDate != null && bsDate.DateValue != null) ? RangeExtensions.FormatValue(bsDate.DateValue) : string.Empty;

            var hiddenTag = new TagBuilder("input");

            hiddenTag.GenerateId(fromName);
            hiddenTag.MergeAttribute("name", fromName);
            hiddenTag.MergeAttribute("value", valFormated);
            hiddenTag.MergeAttribute("type", "hidden");
            hiddenTag.MergeAttributes(htmlAttributes);
            inputHtml.Append(hiddenTag.ToString(TagRenderMode.Normal));

            return(new MvcHtmlString(inputHtml.ToString()));
        }
        internal static MvcHtmlString DateTimeInternal(this HtmlHelper htmlHelper, string name, DateTime?value,
                                                       IDictionary <string, object> htmlAttributes, IDictionary <string, object> dataOptions)
        {
            var inputHtml = new StringBuilder();

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

            if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState))
            {
                if (modelState.Errors.Count > 0)
                {
                    htmlAttributes.MergeAttribute("class", HtmlHelper.ValidationInputCssClassName);
                }
            }

            //Validation Hack
            name = name.Replace(".TextValue", "");

            var attributes = htmlHelper.GetUnobtrusiveValidationAttributes(name);

            if (name.Contains(".") && !attributes.Any())
            {
                attributes = htmlHelper.GetUnobtrusiveValidationAttributes(name.Split('.').LastOrDefault());
            }

            foreach (var item in attributes)
            {
                htmlAttributes.MergeAttribute(item.Key, item.Value.ToString(), true);
            }

            //Set display value
            string displayValue = null;

            if (value.HasValue)
            {
                displayValue = value.Value.ToString();
            }

            //render input type text
            inputHtml.Append(htmlHelper.TextBox(name + ".TextValue", displayValue, htmlAttributes).ToHtmlString());

            //render hidden for range
            htmlAttributes = new Dictionary <string, object>();
            htmlAttributes.MergeAttribute("data-for", name + ".TextValue");

            //From
            var fromName = name + ".DateValue";

            htmlAttributes.MergeAttribute("class", "bs-date-iso", true);

            var valFormated = (value.HasValue) ? RangeExtensions.FormatValue(value) : string.Empty;

            var hiddenTag = new TagBuilder("input");

            hiddenTag.GenerateId(fromName);
            hiddenTag.MergeAttribute("name", fromName);
            hiddenTag.MergeAttribute("value", valFormated);
            hiddenTag.MergeAttribute("type", "hidden");
            hiddenTag.MergeAttributes(htmlAttributes);
            inputHtml.Append(hiddenTag.ToString(TagRenderMode.Normal));

            return(new MvcHtmlString(inputHtml.ToString()));
        }