the server model:
public class BT
{
public IList<B> Bs{ get; set; }
public IList<T> Ts{ get; set; }
}
public class B
{
[Key]
public int BID { get; set; }
[Required]
public string BText { get; set; }
}
public class T
{
[Key]
public int TID { get; set; }
[Required]
public string TText { get; set; }
}
in client I want to return the BT object to server.
function BViewModel() {
var self = this;
self.Bs = ko.observableArray([]);
self.newB = ko.observable("");
self.Ts = ko.observableArray([]);
self.newT = ko.observable("");
self.b= { Bs: self.Bs, Ts: self.Ts};
// Operations
self.save = function () {
$.ajax("/board/Save", {
data: ko.toJSON({ BT: self.b} ),
type: "post",
contentType: "application/json",
success: alert('success');
});
};
}
ko.applyBindings(new BViewModel());
and the server method:
public ActionResult Save(BT b)
{
return view();
}
how should I make self.b= { Bs: self.Bs, Ts: self.Ts}; so the server recognize that? it is null.