using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; using Sleis.ViewModels; using Sleis.Models; namespace Sleis.HtmlHelpers { public static class ToggleHelper { /// /// Creates a previous and next button on the page that will toggle through a list of items to the current controller and action. /// /// /// ///
Previous Next
///
public static string TogglerControl(this HtmlHelper html, ToggleInfo toggle) { return TogglerControl(html, toggle, "Previous", new { @class = "previousButton" }, "Next", new { @class = "nextButton" }); } public static string TogglerControl(this HtmlHelper html, ToggleInfo toggle, string backButtonText, object backButtonHtmlAttributes , string nextButtonText, object nextButtonHtmlAttributes ) { //prevents creating the control if no toggle info has been sent if (toggle != null) { var urlHelper = new UrlHelper(html.ViewContext.RequestContext); TagBuilder backButton = new TagBuilder("a"); backButton.InnerHtml = backButtonText; //create link for previous Id backButton.Attributes.Add("href", toggle.GetPreviousUrl()); backButton.MergeAttributes(new RouteValueDictionary(backButtonHtmlAttributes)); TagBuilder nextButton = new TagBuilder("a"); nextButton.InnerHtml = nextButtonText; //create link for next Id nextButton.Attributes.Add("href", toggle.GetNextUrl()); nextButton.MergeAttributes(new RouteValueDictionary(nextButtonHtmlAttributes)); return String.Format("{0}{1}", toggle.ShowPrevButton() ? backButton.ToString() : "" , toggle.ShowNextButton() ? nextButton.ToString() : ""); } return String.Empty; } } }