///<summary> /// Displays a configurable "Go To Page:" form for instances of PagedList. ///</summary> ///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param> ///<param name="list">The PagedList to use as the data source.</param> ///<param name="formAction">The URL this form should submit the GET request to.</param> ///<param name="options">Formatting options.</param> ///<returns>Outputs the "Go To Page:" form HTML.</returns> public static HtmlString PagedListGoToPageForm(this IHtmlHelper html, IPagedList list, string formAction, GoToFormRenderOptions options) { var htmlHelper = new HtmlHelper(new TagBuilderFactory()); var htmlString = htmlHelper.PagedListGoToPageForm(list, formAction, options); return(new HtmlString(htmlString)); }
public string PagedListGoToPageForm(IPagedList list, string formAction, GoToFormRenderOptions options) { var form = _tagBuilderFactory .Create("form"); form.AddCssClass("PagedList-goToPage"); form.Attributes.Add("action", formAction); form.Attributes.Add("method", "get"); var fieldset = _tagBuilderFactory .Create("fieldset"); var label = _tagBuilderFactory .Create("label"); label.Attributes.Add("for", options.InputFieldName); SetInnerText(label, options.LabelFormat); var input = _tagBuilderFactory .Create("input"); input.Attributes.Add("type", options.InputFieldType); input.Attributes.Add("name", options.InputFieldName); input.Attributes.Add("value", list.PageNumber.ToString()); input.Attributes.Add("class", options.InputFieldClass); input.Attributes.Add("Style", $"width: {options.InputWidth}px"); var submit = _tagBuilderFactory .Create("input"); submit.Attributes.Add("type", "submit"); submit.Attributes.Add("value", options.SubmitButtonFormat); submit.Attributes.Add("class", options.SubmitButtonClass); submit.Attributes.Add("Style", $"width: {options.SubmitButtonWidth}px"); AppendHtml(fieldset, TagBuilderToString(label)); AppendHtml(fieldset, TagBuilderToString(input, TagRenderMode.SelfClosing)); AppendHtml(fieldset, TagBuilderToString(submit, TagRenderMode.SelfClosing)); AppendHtml(form, TagBuilderToString(fieldset)); return(TagBuilderToString(form)); }