Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

"[\"1454\",\"1455\",\"1456\",\"1457\",\"1458\",\"1459\"]"

I am getting a json string in my string variable in a action method that I am sending as json.stringify. These Are the id's of selected rows from jqgrid..

I just want to create an array of the Id's I am getting . I do not want the others like backslash or forward or double qutes.

Can you pl.Help me . How is this possible in C#

Controller::
 public ActionResult ExportSelectedData(string SelectedRows)
        {
}

View Code::
function genGraph() {
        // location.href = "/WebReports/BatchReport";
        var selRowIds = $("#list1").jqGrid('getGridParam', 'selarrrow');
        var Array = JSON.stringify(selRowIds);

        $.ajax({
            type: 'POST',
            url: '/WebReports/ExportSelectedData',
            data: "{'SelectedRows':'" + Array + "'}",
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (returnValue) {
                location.href = "/WebReports/Download?file=" + returnValue.File;
            }
        });
        alert(Array);
share|improve this question
1  
Probably it will be easier for you to use selRowIds.join() (or selRowIds.join(",")) to make string 1454,1455,1456,1457,1458,1459 instead of ["1454","1455","1456","1457","1458","1459"]. So you can use data: {SelectedRows: selRowIds.join()} as parameter of Ajax. On the server side you can use string[] selRows = SelectedRows.split(','); to parse the data. – Oleg Apr 14 '14 at 12:39
    
You can try to use the approach with ModelBinder or simple use object with int[] or string[] as a property here alternatively. – Oleg Apr 14 '14 at 14:49
up vote 3 down vote accepted

this should work use Newtonsoft.Json Library

string[] strings = JsonConvert.DeserializeObject<string[]>(jsonData);

below is the fiddle

http://dotnetfiddle.net/t5kBoy

share|improve this answer
    
Hello Sir. The above thing is working quite well but can it be possible to get the json string in simple string object and not as an string array? – Sweetie Apr 15 '14 at 4:27
    
simple string means? you want comma separated ? – Nilesh Apr 15 '14 at 4:33
    
yes sir.Actually I want it to send to store procedure for using "in" operator.I want to get records from table where Id in(Above array).. – Sweetie Apr 15 '14 at 5:31
    
check the edited fiddle ...and tell if it is correct – Nilesh Apr 15 '14 at 5:39

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.