コード例 #1
0
        /// <summary>
        /// Renders a button which provides an &lt;input&gt; (type=submit) tag (target: controller Http-Post method)
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="type"></param>
        /// <param name="text"></param>
        /// <param name="actionName"></param>
        /// <param name="controllerName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        // ReSharper disable once UnusedParameter.Global
        public static MvcHtmlString SubmitButton <TModel>(this HtmlHelper <TModel> htmlHelper,
                                                          ButtonType type,
                                                          string text)
        {
            var htmlAttributes = HtmlExtensions.GetButtonHtmlAttributes(type);

            var b = new TagBuilder("input");

            b.MergeAttribute("type", "submit");
            b.MergeAttribute("value", text);
            b.MergeAttributes <string, object>(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));

            var s = new MvcHtmlString(b.ToString(TagRenderMode.SelfClosing));

            return(s);
        }
コード例 #2
0
        /// <summary>
        /// Renders a button which provides an &lt;a&gt; tag (target: controller Http-Get method)
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="type"></param>
        /// <param name="text"></param>
        /// <param name="actionName"></param>
        /// <param name="controllerName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static MvcHtmlString LinkButton <TModel>(this HtmlHelper <TModel> htmlHelper,
                                                        ButtonType type,
                                                        string text,
                                                        [AspMvcAction]
                                                        string actionName,
                                                        [AspMvcController]
                                                        string controllerName = null,
                                                        object id             = null)
        {
            var htmlAttributes = HtmlExtensions.GetButtonHtmlAttributes(type);

            if (id != null)
            {
                object routeValues = new { id = id };
                return(htmlHelper.ActionLink(text, actionName, controllerName, routeValues, htmlAttributes));
            }
            else
            {
                return(htmlHelper.ActionLink(text, actionName, controllerName, htmlAttributes));
            }
        }