/// <summary>
        /// Create the text-box and hidden field that is also has validation hooked up
        /// </summary>
        /// <typeparam name="TModel">The model</typeparam>
        /// <typeparam name="TProperty">The property to display in the text-box</typeparam>
        /// <typeparam name="TKey">The id in the hidden field</typeparam>
        /// <param name="htmlHelper">The helper</param>
        /// <param name="nameExpression">The expression for the string in the text-box</param>
        /// <param name="hiddenFor">The expression for the hidden field id</param>
        /// <returns></returns>
        public static MvcHtmlString AutoCompleteFor <TModel, TProperty, TKey>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > nameExpression, Expression <Func <TModel, TKey> > hiddenFor)
        {
            var textbox     = BootstrapTextBoxHelper.BootstrapTextBoxFor(htmlHelper, nameExpression).ToHtmlString();
            var hiddenField = HtmlHiddenHelperFor.CleanHiddenFor(htmlHelper, hiddenFor).ToHtmlString();

            return(new MvcHtmlString(string.Format("{0} {1}", textbox, hiddenField)));
        }
Esempio n. 2
0
        /// <summary>
        /// Create the text-box and hidden field that is also has validation hooked up
        /// </summary>
        /// <typeparam name="TModel">The model</typeparam>
        /// <typeparam name="TProperty">The property to display in the text-box</typeparam>
        /// <typeparam name="TKey">The id in the hidden field</typeparam>
        /// <param name="htmlHelper">The helper</param>
        /// <param name="nameExpression">The expression for the string in the text-box</param>
        /// <param name="hiddenFor">The expression for the hidden field id</param>
        /// <returns></returns>
        public static IHtmlContent AutoCompleteFor <TModel, TProperty, TKey>(this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > nameExpression, Expression <Func <TModel, TKey> > hiddenFor)
        {
            var textbox     = Utils.GetString(BootstrapTextBoxHelper.BootstrapTextBoxFor(htmlHelper, nameExpression));
            var hiddenField = Utils.GetString(HtmlHiddenHelperFor.CleanHiddenFor(htmlHelper, hiddenFor));

            return(new HtmlString(string.Format("{0} {1}", textbox, hiddenField)));
        }
        /// <summary>
        /// Create an Auto-complete text-box for a specific property for a model
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="expression"></param>
        /// <param name="textBoxId">The Id of the text-box</param>
        /// <param name="textBoxValue">The initial value of the text-box</param>
        /// <param name="hiddenFieldId">The Id of the hidden value</param>
        /// <param name="hiddenFieldValue">The initial value of the hidden field</param>
        /// <returns></returns>
        public static MvcHtmlString AutoCompleteFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string textBoxId, string textBoxValue, string hiddenFieldId, string hiddenFieldValue)
        {
            var values = new Dictionary <string, object>();

            values.Add("id", textBoxId);
            values.Add("value", textBoxValue);
            var textBox = BootstrapTextBoxHelper.BootstrapTextBoxFor(htmlHelper, expression, values).ToHtmlString();
            var hidden  = string.Format("<input type=\"hidden\" id=\"{0}\" name=\"{0}\" value=\"{1}\" />", hiddenFieldId, hiddenFieldValue);

            return(new MvcHtmlString(string.Format("{0}{1}", textBox, hidden)));
        }