Mvc Html.ActionButton

前端 未结 7 1969
鱼传尺愫
鱼传尺愫 2020-12-16 01:52

Has anyone written one? I want it to behave like a link but look like a button. A form with a single button wont do it has I don\'t want any POST.

7条回答
  •  死守一世寂寞
    2020-12-16 02:25

    Code for Tomas' answer:

    public static class HtmlExtensions
    {
      public static string ActionButton(this HtmlHelper helper, string value, 
          string action, string controller, object routeValues)
      {
        UrlHelper urlHelper = new UrlHelper(helper.ViewContext);
        var action = urlHelper.Action(action, controller, routeValues);
    
        var html = new StringBuilder();
        html.AppendFormat("
    ", action).AppendLine() .AppendFormat(" ", value).AppendLine() .AppendFormat("
    ").AppendLine(); return html.ToString(); } }

提交回复
热议问题