Ajax.ActionLink(...)使用复选框 [英] Ajax.ActionLink(...) with checkbox

查看:100
本文介绍了Ajax.ActionLink(...)使用复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ajax.ActionLink("Link name",....)

有可能把复选框到位链接名称的?

it is possible to put checkbox in place of "Link name" ?

如果又如何?

感谢

推荐答案

是的,当然,这是可能的。你可以使用一个标准的复选框:

Yes, of course that it is possible. You could use a standard checkbox:

@Html.CheckBoxFor(
    x => x.Foo, 
    new { 
        data_url = Url.Action("SomeAction", "SomeController"), 
        id = "mycheckbox" 
    }
)

,然后在单独的JavaScript文件中使用jQuery订阅此复选框的变化事件,并悄悄地AJAXify它:

and then in your separate javascript file use jQuery to subscribe to the change event of this checkbox and unobtrusively AJAXify it:

$(function() {
    $('#mycheckbox').change(function() {
        var data = {};
        data[$(this).attr('name')] = $(this).is(':checked');

        $.ajax({
            url: $(this).data('url'),
            type: 'POST',
            data: data,
            success: function(result) {
                // TODO: do something with the result    
            }
        });
    });
});

这篇关于Ajax.ActionLink(...)使用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆