Ajax.ActionLink (...) with checkbox

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

can I check the box for "Link name"?

if so how?

thanks,

+2
source share
1 answer

Yes, of course, it is possible. You can use the standard checkbox:

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

and then in your separate javascript file use jQuery to subscribe to the event this flag changes and unobtrusively AJAXify:

 $(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 } }); }); }); 
+3
source

Source: https://habr.com/ru/post/1233735/


All Articles