observable array to c# list

759 views
Skip to first unread message

wallace....@gmail.com

unread,
Jul 10, 2012, 7:04:19 PM7/10/12
to knock...@googlegroups.com
I am having difficulty passing my object to my C# controller.  everything else is coming across as it should but my array is not. any help to fix my issue would be helpful.  when i pass everything though ajax i can see that all the data is there in the POST but when i hit the break point in my controller everything is there as it should be except this array.  

bits and pieces of the VM and Model.

VM:

var Model = {

 bool1: ko.observable(false),
    bool2: ko.observable(false),
    type: ko.observable('TCPIP'),
bigsmile: ko.observableArray([])
}

Model

  public bool bool1;
 public bool bool2;
public string type;
 public List<Entry> bigsmile;

nishant sharma

unread,
Jul 11, 2012, 12:52:55 AM7/11/12
to knock...@googlegroups.com
you should have same object in bigsmile array as you have in entry .

example entry has property like this
public class entry
{

}
--
Nishant

nishant sharma

unread,
Jul 11, 2012, 12:57:33 AM7/11/12
to knock...@googlegroups.com
On Wed, Jul 11, 2012 at 10:22 AM, nishant sharma <nisha...@gmail.com> wrote:
you should have same object in bigsmile array as you have in entry .

example entry has property like this
public class entry
{
  public string FirstName{ get; set;}
     public string LastName{get; set;} 
}
so in bigsmile array you should also pass same type of JavaScript object like this
 var myinfo = function(fname, lname){
  this.FirstName=fname;
this.LastName = lname;
}  
you have to add this object to your bigsmile array 
like this 
bigsmile.push(new myinfo("John","d");

On Wed, Jul 11, 2012 at 4:34 AM, <wallace....@gmail.com> wrote:
I am having difficulty passing my object to my C# controller.  everything else is coming across as it should but my array is not. any help to fix my issue would be helpful.  when i pass everything though ajax i can see that all the data is there in the POST but when i hit the break point in my controller everything is there as it should be except this array.  

bits and pieces of the VM and Model.

VM:

var Model = {

 bool1: ko.observable(false),
    bool2: ko.observable(false),
    type: ko.observable('TCPIP'),
bigsmile: ko.observableArray([])
}

Model

  public bool bool1;
 public bool bool2;
public string type;
 public List<Entry> bigsmile;



--
Nishant



--
Nishant

wallace....@gmail.com

unread,
Jul 11, 2012, 10:08:19 AM7/11/12
to knock...@googlegroups.com
More Details

here is the model

    public class Entry
    {
        
        public string table{get;set;}
        public string site{get;set;}
        public string value1{get;set;}
        public string value2 { getset; }
   
    } 

here is the json
,"bigsmile":[{"table":"http.tbl","site":"google.com","value1":"value 3","value2":"value 4"}]

when i look at the json transmitted to the controller everything looks fine.  but when i look at the controller bigsmile has a count of 0.

thanks for the help.

jean.seba...@gmail.com

unread,
Jul 14, 2012, 7:44:40 PM7/14/12
to knock...@googlegroups.com
Having the controller code might be helpful. Usually, when this happens, it is because the parameter in your controller method is not called exactly like the name of the variable being passed as json. Have you tried to name the parameter "bigsmile" in your controller?
Reply all
Reply to author
Forward
0 new messages