Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

What I tried in my project is like passing checkbox's selected value as a comma separated string to json of my controller.. but i'm not getting a value to the json action.. it shows null over there.

How can I do this? Please help me

function getIds(checkList) 
{
    var idList = new Array();
    var loopCounter = 0;
    jQuery("input[name=" + checkList + "]:checked").each
    (
        function() 
        {
           idList[loopCounter] = jQuery(this).val();
           loopCounter += 1; 
        }
    );
       alert(idList);
          jQuery.getJSON("/Photos/CheckForIdsJson", { idList: idList });     
 }

 [AcceptVerbs(HttpVerbs.Get)]        
 public JsonResult CheckForIdsJson(Int32[] idList)
 {
       JsonResult result = new JsonResult();
        result.Data = idList;
         return result;
 }
share|improve this question
    
Where do you see the null value, in idList in you js file, in controller code or in return resul tback in your js code? –  Jani Jan 12 '12 at 9:43
    
maybe you can take a look at this: stackoverflow.com/questions/536283/…. –  JoJa Jan 12 '12 at 9:44
    
Put some alerts in your code to evaluate the status of the array, and use Firebug to evaluate the code to determine when/where you are losing your values in the idlist. Once you know where the problem occurs, you can focus on the JSON aspect. –  jamesTheProgrammer Jan 12 '12 at 14:47
    
in my controller code.. in javascript where i put the alert , i m geting idlist value but null in controller's action. –  lakhani Jan 13 '12 at 10:33
    
uys, for what i was doing this is to delete multiple selction checkbox and pass the string to json .....now i done this.. – Labdhi Lakhani 3 mins ago edit but what i wanna do now like in json method (/Photos/CheckForIdsJson) i delete sme recrds from db as wel as model.. bt i couldnt return view to other view in same controller.. i m doing like after deletion other view called "PhotoList" should b called to list the items with changes done –  lakhani Jan 13 '12 at 12:41

2 Answers 2

up vote 0 down vote accepted

You can have a look at this post : AJAX Post of JavaScript String Array to JsonResult as List<string> Always Returns Null? or this one : Send list/array as paramater with jQuery getJson . It seems that you have to indicate traditional: true in your ajax call.

share|improve this answer
    
guys, for what i was doing this is to delete multiple selction checkbox and pass the string to json .....now i done this.. –  lakhani Jan 13 '12 at 12:36
    
but what i wanna do now like in json method (/Photos/CheckForIdsJson) i delete sme recrds from db as wel as model.. bt i couldnt return view to other view in same controller.. i m doing like after deletion other view called "PhotoList" should b called to list the items with changes done.. –  lakhani Jan 13 '12 at 12:39
    
Have you try a return RedirectToAction("yourAction", "yourController"); instead of returning your result? –  Samuel Caillerie Dec 4 '12 at 9:22

Use this in your script :

var did ='',
$("#tbl").find("input:checkbox").each(function (i) {
    if (this.checked == true) {
        did += $(this).val() + ",";
    }
});

alert(did); 

if (did == "") {
    alert("Please Select"); 
    return; 
} 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.