// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Web.Mvc; namespace Microsoft.Web.Mvc { public static class ButtonsAndLinkExtensions { /// /// Creates a submit button for your form /// /// The helper which we extend. /// The name. /// public static MvcHtmlString SubmitButton(this HtmlHelper helper, string name) { return SubmitButton(helper, name, null, null); } /// /// Creates a submit button for your form /// /// The helper which we extend. /// The name. /// The text for the button face /// public static MvcHtmlString SubmitButton(this HtmlHelper helper, string name, string buttonText) { return SubmitButton(helper, name, buttonText, null); } /// /// Creates a submit button for your form /// /// The helper which we extend. public static MvcHtmlString SubmitButton(this HtmlHelper helper) { return SubmitButton(helper, null, null, null); } /// /// Creates a submit button for your form /// /// The helper which we extend. /// Name of the button /// The text for the button face /// Any attributes you want set on the tag. Use anonymous-type declaration for this: new{class=cssclass} /// public static MvcHtmlString SubmitButton(this HtmlHelper helper, string name, string buttonText, object htmlAttributes) { return helper.SubmitButton(name, buttonText, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } /// /// Creates a submit button for your form /// /// The helper which we extend. /// Name of the button /// The text for the button face /// Dictionary of HTML settings /// [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "helper", Justification = "Required for Extension Method")] public static MvcHtmlString SubmitButton(this HtmlHelper helper, string name, string buttonText, IDictionary htmlAttributes) { return MvcHtmlString.Create(ButtonBuilder.SubmitButton(name, buttonText, htmlAttributes).ToString(TagRenderMode.SelfClosing)); } /// /// Creates a submit button for your form using an image /// /// The helper which we extend. /// Name of the button /// The URL for the image /// public static MvcHtmlString SubmitImage(this HtmlHelper helper, string name, string imageSrc) { return helper.SubmitImage(name, imageSrc, null); } /// /// Creates a submit button for your form using an image /// /// The helper which we extend. /// Name of the button /// The URL for the image /// Any attributes you want set on the tag. Use anonymous-type declaration for this: new{class=cssclass} /// public static MvcHtmlString SubmitImage(this HtmlHelper helper, string name, string imageSrc, object htmlAttributes) { return helper.SubmitImage(name, imageSrc, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } /// /// Creates a submit button for your form using an image /// /// The helper which we extend. /// Name of the button /// The URL for the image /// Dictionary of HTML settings /// public static MvcHtmlString SubmitImage(this HtmlHelper helper, string name, string imageSrc, IDictionary htmlAttributes) { if (imageSrc == null) { throw new ArgumentNullException("imageSrc"); } string resolvedUrl = UrlHelper.GenerateContentUrl(imageSrc, helper.ViewContext.HttpContext); return MvcHtmlString.Create(ButtonBuilder.SubmitImage(name, resolvedUrl, htmlAttributes).ToString(TagRenderMode.SelfClosing)); } /// /// A Simple button you can use with javascript /// /// The helper which we extend. /// Name of the button /// The text for the button face /// The button type (Button, Submit, or Reset) /// public static MvcHtmlString Button(this HtmlHelper helper, string name, string buttonText, HtmlButtonType buttonType) { return helper.Button(name, buttonText, buttonType, null, (IDictionary)null); } /// /// A Simple button you can use with javascript /// /// The helper which we extend. /// Name of the button /// The text for the button face /// The button type (Button, Submit, or Reset) /// The method or script routine to call when the button is clicked. /// public static MvcHtmlString Button(this HtmlHelper helper, string name, string buttonText, HtmlButtonType buttonType, string onClickMethod) { return helper.Button(name, buttonText, buttonType, onClickMethod, (IDictionary)null); } /// /// A Simple button you can use with javascript /// /// The helper which we extend. /// Name of the button /// The text for the button face /// The button type (Button, Submit, or Reset) /// The method or script routine to call when the button is clicked. /// Any attributes you want set on the tag. Use anonymous-type declaration for this: new{class=cssclass} /// public static MvcHtmlString Button(this HtmlHelper helper, string name, string buttonText, HtmlButtonType buttonType, string onClickMethod, object htmlAttributes) { return helper.Button(name, buttonText, buttonType, onClickMethod, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } /// /// A Simple button you can use with javascript /// /// The helper which we extend. /// Name of the button /// The text for the button face /// The button type (Button, Submit, or Reset) /// The method or script routine to call when the button is clicked. /// Any attributes you want set on the tag. Use anonymous-type declaration for this: new{class=cssclass} /// [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "helper", Justification = "This is an Extension Method and requires this argument")] public static MvcHtmlString Button(this HtmlHelper helper, string name, string buttonText, HtmlButtonType buttonType, string onClickMethod, IDictionary htmlAttributes) { return MvcHtmlString.Create(ButtonBuilder.Button(name, buttonText, buttonType, onClickMethod, htmlAttributes).ToString(TagRenderMode.Normal)); } } }