views:

33

answers:

1

Hi all,

I have a link to delete action using Jquery dialog confirm message. Clicking on delete link, a modal popup is showing with a confirmation question. Button Yes is triggered to submit the form with 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>

this work fine.

Now instead of this I want just to write a Html helper wich will do this work, something like

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

the js is:

$('#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"); }
    }
});

So is it possible to write such helper and if it is posible please give some tips, Thanks

+1  A: 

You would need to write an extension method for the HtmlHelper class. Something like this:

public class HtmlExtensions
{
    public static string DeleteActionLink<TController>(this HtmlHelper helper, Expression<Action<TController>> action, string text)
    {
        // Construct output and return string
    }
}
roryf
This is clear, but who to use BeginForm and how to create that href?your code: // Construct output and return string - this is main question :)
isuruceanu