sql - MVC Get value of a column in a row in a table where checkbox is checked and store in list using JQuery -


i'm working on first large mvc project , i'm having trouble working out how value of date column, each row in table, rows check box checked/selected , store in list (preferably in homecontroller)

i found : getting id of table row when checkbox checked

which lead me trying number of changes below

$("#thechecked").click(function(){ var closesttr = $(':checkbox:checked').closest('tr'); alert(closesttr); }); 

but [object object]

my table (can have several thousand rows):

<table class="table">   <thead>     <tr>       <th></th>       <th>date</th>       <th>test type</th>     </tr>   </thead>   <tbody>     @foreach (var item in model)     {       <tr>         <td>           <input type="checkbox" class="checks">         </td>         <td>           @html.displayfor(modelitem => item.creationdatetime)         </td>         <td>           @html.displayfor(modelitem => item.appmodeid)         </td>       </tr>     }   </tbody> </table> 

also note above table within modal.

can suggest suitable method produce this? or point me in right direction?

edit: using method return dates in array, im looking find out how post list in controller using ajax?

    $("#resultsgo").click(function () {         $('.checks:checked').each(function () {             var createdate = $(this).closest('tr').children('td').eq(1).text();             var datearray = [];             datearray.push(createdate); // testing         });     }); 

controller :

    public actionresult index(string filtername)             {         httpcookie cookieuser = request.cookies["logincookie"];         viewbag.username = server.htmlencode(cookieuser.value);          var filterresults = m in db.userinfoes                             select m;          filterresults = filterresults.where(x => x.usercode.tostring().contains(filtername)).orderby(x => x.usercode);         checkdownloaded();         return view(filterresults);     } 

in order value of creationdatetime each row checkbox checked can use (i assume #thechecked must id of button or other element on page)

$("#thechecked").click(function() {   var selecteddates = new array();   $('.checks:checked').each(function() {     var createdate = $(this).closest('tr').children('td').eq(1).text();     selecteddates.push(createdate); // add array   });   $.ajax({     type: "post",     url: '@url.action("savedates")';     datatype: "json",     traditional: true,     data: {dates: selecteddates },     success: function(data) {       // returned value?     }   }); }); 

this may depend on displaytemplate rendering , may better use following add value in table cell

<td>   @item.creationdatetime </td> 

controller

[httppost] public jsonresult savedates(ienumerable<datetime> dates) {   foreach(datetime date in dates)   {     // date   }   return json(somereturnvalue); } 

you indicated table might "have several thousand rows". if case, should consider paging display 20-50 rows @ time improve performance.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -