Looking for a Html.SubmitButton helper that would accept class attributes in MVC3

后端 未结 6 1314
野性不改
野性不改 2020-12-31 08:42

I would like to use a helper for Submit button in MVC3. Is such a thing available? If not, then does anyone know where I could get some code for this. I would like one that

6条回答
  •  一个人的身影
    2020-12-31 09:10

    Just add to your project class with such code:

    using System.Text;
    
    namespace System.Web.Mvc
    {
    public static class CustomHtmlHelper
    {
        public static MvcHtmlString SubmitButton(this HtmlHelper helper, string buttonText, object htmlAttributes = null)
        {
            StringBuilder html = new StringBuilder();
            html.AppendFormat("");
            return new MvcHtmlString(html.ToString());
        }
    }
    }
    

    And usage example:

    @Html.SubmitButton("Save", new { @class= "btn btn-default", id="create-button" })
    

提交回复
热议问题