开发者

Manage 2 or 3 functionalities on checked elements in a table

I have a page with a list of items (tabular presentation). On each line in this table, I have a checkbox. The user can check some elements and submit the form for adding these elements to his favorites. It works for this functionnality. Now I would like to add other functionalities like 'delete selected elements' or 'mail selected elements'. I don't know how to proceed... Any help will be highly appreciated.

Below is my view page:

<% using (Html.BeginForm("AddCheckedItemsToFavorites","Home",FormMethod.Post, new { id="form1" } )) { %>
    <table class="search-results">                                
        <% foreach (var affaire in Model.AffairePagingResult.Items) { %>
            <tr>
                <td class="checkbox">
                    <input type="checkbox" name="checkbox" class="checkbox" value="<%= affaire.IdAffaire%>" />
                </td>
                <td class="favoricon">
                    <%= Html.ImageFavorite(affaire) %>
                </td>
            </tr>
        <% } %>
    </table>
<% } %>

Below is my controller:

[Authorize, HttpPost] 
public ActionResult AddCheckedItemsToFavorites(string[] c开发者_JAVA技巧heckbox)
{
    if (checkbox != null)
    {
        foreach (string item in checkbox)
        {
             // do some stuff here
        }
    }
    // go back...
}


Try :

Html.ActionLink("Add To Favorites", 
   new { controller = "Home", action = "AddCheckedItemsToFavorites", id = "form1" })

and

Html.ActionLink("Delete", 
       new { controller = "Home", action = "DeleteCheckedItems", id = "form1" })

instead of setting action to your form, just use a simple form tag


Finally, I found a solution as explained below. I trigger a specific button for each situation. In my controller, I can call a specific action. Thank you anyway.

My view page:

<% using (Html.BeginForm("ManageCheckedItems", "Home",FormMethod.Post)) { %>
    // manage checkbox or other stuff here in a table...                    
    <input type="submit" class="hidden-submit-button" name="submitFavor" />
    <input type="submit" class="hidden-submit-button" name="submitEmail" />
<% } %>    

My jQuery script:

    $("#add-to-favorites").click(function () {
        $("input[name='submitFavor']").trigger('click');
    });

    $("#send-by-mail").click(function () {
        $("input[name='submitEmail']").trigger('click');
    });

My controller:

    [Authorize, HttpPost]
    public void ManageCheckedItems(string[] checkbox, string submitFavor, string submitEmail)
    {
        if (submitFavor != null) AddCheckedItemsToFavorite(checkbox);
        if (submitEmail != null) SendCheckedItemsByEmail(checkbox);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜