public static MvcHtmlString ListBox(this AjaxHelper ajaxHelper, string name, IEnumerable <SelectListItem> selectList = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?size = null, string style = null, int?tabIndex = null, string title = null, string dataBind = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); if (dataBind == null) { dataBind = "value: " + name; } return(htmlHelper.ListBox( name, selectList, SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title, dataBind))); }
public static MvcHtmlString EnableSubmit(this AjaxHelper ajaxHelper, string formName, string controller, string processMethod = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("$('" + formName + "').submit(function (e) {"); sb.AppendLine("\te.preventDefault();"); sb.AppendLine("\t$.ajax({"); sb.AppendLine( "\t\turl: '" + new UrlHelper(HttpContext.Current.Request.RequestContext).Action(controller) + "',"); sb.AppendLine("\t\ttype: 'POST',"); sb.AppendLine("\t\tdataType: 'json',"); sb.AppendLine("\t\tdata: $(this).serialize(),"); sb.AppendLine("\t\tsuccess: function (data) {"); if (!String.IsNullOrEmpty(processMethod)) { sb.AppendLine("\t\t\t" + processMethod + "(data);"); } else { // default behavior sb.AppendLine("\t\t\talert('saved');"); } sb.AppendLine("\t\t}"); sb.AppendLine("\t});"); sb.AppendLine("\treturn false;"); sb.AppendLine("});"); return(MvcHtmlString.Create(sb.ToString())); }
public static MvcHtmlString Action(this AjaxHelper ajaxHelper, string actionName, string controllerName = null, object routeValues = null) { return(ajaxHelper.GetHtmlHelper().Action(actionName, controllerName, routeValues)); }
public static MvcHtmlString TextBox(this AjaxHelper ajaxHelper, string name, object value = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?maxLength = null, bool readOnly = false, int?size = null, string style = null, int?tabIndex = null, string title = null, string dataBind = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); if (dataBind == null) { dataBind = "value: " + name; } return(htmlHelper.TextBox( name, value, InputAttributes( name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind))); }
public static MvcHtmlString DropDownListFor <TModel, TProperty>(this AjaxHelper <TModel> ajaxHelper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList = null, string optionLabel = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?size = null, string style = null, int?tabIndex = null, string title = null, string dataBind = null) { HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper(); string name = ExpressionHelper.GetExpressionText(expression); if (dataBind == null) { dataBind = "value: " + name; } return(htmlHelper.DropDownList( name, selectList, optionLabel, SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title, dataBind))); }
public static MvcHtmlString CheckBoxFor <TModel>(this AjaxHelper <TModel> ajaxHelper, Expression <Func <TModel, bool> > expression, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?maxLength = null, bool readOnly = false, int?size = null, string style = null, int?tabIndex = null, string title = null, string dataBind = null) { HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper(); string name = ExpressionHelper.GetExpressionText(expression); if (dataBind == null) { dataBind = "checked: " + name; } return(htmlHelper.CheckBoxFor( expression, InputAttributes( name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind))); }
public static MvcHtmlString RadioButton(this AjaxHelper ajaxHelper, string name, object value, bool?isChecked = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?maxLength = null, bool readOnly = false, int?size = null, string style = null, int?tabIndex = null, string title = null, string dataBind = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); if (dataBind == null) { dataBind = "checked: " + name; } IDictionary <string, object> htmlAttributes = InputAttributes( name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind); return(isChecked.HasValue ? htmlHelper.RadioButton(name, value, isChecked.Value, htmlAttributes) : htmlHelper.RadioButton(name, value, htmlAttributes)); }
public static MvcHtmlString DisplayForModel(this AjaxHelper ajaxHelper, string templateName = null, string htmlFieldName = null, string dataBind = null) { //todo See what to do with that HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); return(htmlHelper.DisplayForModel(templateName, htmlFieldName)); }
public static MvcHtmlString EnableRefresh(this AjaxHelper ajaxHelper, string elementName, string controller, string processMethod = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("$('#" + elementName + "').click(function (e) {"); sb.AppendLine("\t$.ajax({"); sb.AppendLine( "\t\turl: '" + new UrlHelper(HttpContext.Current.Request.RequestContext).Action(controller) + "',"); sb.AppendLine("\t\ttype: 'GET',"); sb.AppendLine("\t\tdataType: 'json',"); sb.AppendLine("\t\tdata: null,"); sb.AppendLine("\t\tsuccess: function (data) {"); if (!String.IsNullOrEmpty(processMethod)) { sb.AppendLine("\t\t\t" + processMethod + "(data);"); } else { // default behavior is to copy to ViewModel sb.AppendLine("\t\t\tvar parsed=JSON.parse(data);"); object model = ajaxHelper.ViewData.Model; Type type = model.GetType(); string name = type.Name; PropertyInfo[] props = type.GetProperties(); foreach (PropertyInfo prop in props) { if (prop.PropertyType.IsArray || prop.PropertyType.IsConstructedGenericType) { continue; } sb.AppendLine("\t\t\twindow.vm." + prop.Name + "(parsed." + prop.Name + ");"); } // sb.AppendLine("\t\t\tko.applyBindings(" + name + ");"); } sb.AppendLine("\t\t}"); sb.AppendLine("\t});"); sb.AppendLine("\treturn false;"); sb.AppendLine("});"); return(MvcHtmlString.Create(sb.ToString())); }
public static MvcHtmlString Hidden(this AjaxHelper ajaxHelper, string name, object value = null, string cssClass = null, string id = null, string style = null, string dataBind = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); if (dataBind == null) { dataBind = "value: " + name; } return(htmlHelper.Hidden(name, value, Attributes(cssClass, id, style, dataBind))); }
public static MvcHtmlString HiddenFor <TModel, TProperty>(this AjaxHelper <TModel> ajaxHelper, Expression <Func <TModel, TProperty> > expression, string cssClass = null, string id = null, string style = null, string dataBind = null) { HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper(); string name = ExpressionHelper.GetExpressionText(expression); if (dataBind == null) { dataBind = "value: " + name; } return(htmlHelper.HiddenFor(expression, Attributes(cssClass, id, style, dataBind))); }
public static MvcHtmlString MapModelToKnockout(this AjaxHelper ajaxHelper, object model = null) { if (model == null) { model = ajaxHelper.ViewData.Model; } Type type = model.GetType(); string name = type.Name; var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("window.vm = ko.mapping.fromJS(" + ajaxHelper.GetHtmlHelper().Raw(model.ToJson()) + ");"); sb.AppendLine("ko.applyBindings(window.vm);"); return(MvcHtmlString.Create(sb.ToString())); }
// DisplayTextExtensions public static MvcHtmlString DisplayText(this AjaxHelper ajaxHelper, string name, string dataBind = null, string wrapperTag = null) { HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper(); if (dataBind == null) { dataBind = "text: " + name; } if (wrapperTag == null) { wrapperTag = "span"; } return (MvcHtmlString.Create( string.Format( "<{0} data-bind=\"{1}\">{2}</{0}>", wrapperTag, dataBind, htmlHelper.DisplayText(name)))); }
public static MvcHtmlString DisplayFor <TModel, TValue>(this AjaxHelper <TModel> ajaxHelper, Expression <Func <TModel, TValue> > expression, string templateName = null, string htmlFieldName = null, string dataBind = null, string wrapperTag = null) { HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper(); string name = ExpressionHelper.GetExpressionText(expression); if (dataBind == null) { dataBind = "text: " + name; } if (wrapperTag == null) { wrapperTag = "span"; } return (MvcHtmlString.Create( string.Format( "<{0} data-bind=\"{1}\">{2}</{0}>", wrapperTag, dataBind, htmlHelper.DisplayFor(expression)))); }