代码之家  ›  专栏  ›  技术社区  ›  isuruceanu

html.deleteActionLink帮助程序

  •  2
  • isuruceanu  · 技术社区  · 15 年前

    我有一个使用jquery对话框确认消息删除操作的链接。单击删除链接,将显示一个带有确认问题的模式弹出窗口。触发按钮“是”提交id=model.id的表单

    <td>
        <% using (Html.BeginForm<AssessorActionPlanController>(
               c => c.Delete(Model.Id), FormMethod.Post, new { id = Model.Id }))
           { %> <%= Html.AntiForgeryToken()%>
               <a href="#" onclick="ConfirmeDialog('<%= Model.Id.ToString() %>');">
                  Delete
               </a>
        <% } %>
    </td>
    

    这个工作很好。

    现在,我想写一个HTML助手来代替它,wich将完成这项工作,比如

    <td>
        <%= Html.DeleteActionLink<ControllerName>(
            c => c.Delete(Model.Id), "Delete"
        ); %>
    </td>
    

    JS是:

    $('#deleteDialog').html('Are you sure you want to delete this item ?');
    $('#deleteDialog').dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        buttons: {
            'Yes': function() {
                $(this).dialog('close');
                $("form[id='" + submitFormHandler + "']").submit();
    
            },
            'No': function() { $(this).dialog("close"); }
        }
    });
    

    有没有可能写这样的助手,如果可以的话,请给点提示,谢谢。

    1 回复  |  直到 15 年前
        1
  •  1
  •   roryf    15 年前

    您需要为htmlhelper类编写一个扩展方法。像这样:

    public class HtmlExtensions
    {
        public static string DeleteActionLink<TController>(this HtmlHelper helper, Expression<Action<TController>> action, string text)
        {
            // Construct output and return string
        }
    }
    
    推荐文章