Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have used checkbox onselectedindexchange event in updatepanel using listview in asp.net framework 3.5

But now i m developing in mvc razor 4,

and i have listview (using foreach in html) , and want to use checkbox onclick , filter listview and display new results.also when new results are displayed,the whole page should not be refreshed, only listview should be refreshed......

also if checkbox in unchecked , the result should again be filtered without checkbox value and display..

How to do this in MVC razor 4 asp.net c#
Posted
Comments
[no name] 15-Jul-14 7:24am    
you can do it in jquery

1 solution

Razor and c# are server side. Ajax is client side.

I think the path of least resistance for someone from web forms is a set of tools like Telerik[^]


If not, then you can always make a controller endpoint that uses a JsonResult rather than an ActionResult. You can call it from jquery (or regular javascript) and update the page with the results.

JavaScript
function foo(){
    $.ajax({
      url:'yourendpoint',
      data:{arg1:value},
      success:function(data){
           //update your html here
      }
    });
}


C#
public JsonResult MyEndpoint(/*args here*/)
{
  //do your programming to get the data
  var myData = /*result of your program query*/
  return Json(myData,JsonBehavior.AllowGet);
}



You can get much more complex with ajax forms, etc... but I think that is the easiest way to explain it.
 
Share this answer
 
Comments
maulikshah1990 16-Jul-14 0:58am    
One problem i have is , i have multiple checkboxes , like

<input type="checkbox" name="stars[]" value="1" />1

<input type="checkbox" name="stars[]" value="2" />2

<input type="checkbox" name="stars[]" value="3" />3

<input type="checkbox" name="stars[]" value="4" />4

<input type="checkbox" name="price[]" value="121" />121

<input type="checkbox" name="price[]" value="254" />254

<input type="checkbox" name="price[]" value="312" />312

<input type="checkbox" name="price[]" value="410" />410

I want to use both checkbox values , i.e when any of price[] and stars[] is checked , call function from controller and filter table according to checkbox values.

if any checkbox unchecked / checked ,call controller function , and filter values ..

I Hope u understood what i mean ????

How to use ajax to get values from both checkbox list ,and then call same controller function ,
so that datatable return is filtered using both checkbox list , or etc...etc...
loctrice 16-Jul-14 8:19am    
You use jquery to get the values from the checked checkboxes similar to http://stackoverflow.com/questions/786142/how-to-retrieve-checkboxes-values-in-jquery . Then you take the values and put them in the data section of your ajax call. You will also need to add them to your mvc controller so it has a place to map them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900