0

I have tried like this but could not get array list. It returns 'null'

 var data=[];
 data[0] = '1';
 data[1] = '2';
    $.ajax({                    
         url: '@Url.Action("AddFrequencyWeekly", "Plannar")',
         type: "POST",                     
         data: { data: data },
         dataType: 'json', 
         success: function (data) {                                            
             alert("Record Updated Successfully");    
                 }
         });

my model class code following

 public JsonResult AddFrequencyWeekly(string[] data)
        {

}

data value says 'null'

please help me?

2 Answers 2

1
var datas = { data0: '1',
      data1: '2' };
$.ajax({                    
         url: '@Url.Action("AddFrequencyWeekly", "Plannar")',
         type: "POST",                     
         data: datas,
         dataType: 'json', 
         success: function (data) {                                            
             alert("Record Updated Successfully");    
                 }
         });
Sign up to request clarification or add additional context in comments.

12 Comments

i cant get it. this could not redirect to that url page
@Sajith no this will asynchronously send the array datas to server. for example if you are using django you can get this array datas as request.POST['data0']
Hello suhail your code note working well how to solve this issue. could you please post that updated code
@Sajith could you please let me know what proggramming language you are using. i don't familiar with '@Url.Action("AddFrequencyWeekly", "Plannar")', . may be that might be wrong. i am good at django
using asp.net mvc4 and jquery
|
0

Its the way you are expecting to recive the data in the action method, try

public JsonResult AddFrequencyWeekly(IEnumeable<string> data)
{

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.