Post knockout observable array as object property asp.net mvc

AlineeApove

New Member
I'm trying to post an ko.observable array as part of of an object, all that data reaches the server ok except for the array which is not null but has a count of zero.This is on the client side\[code\] function submitAsync() { var viewModel = constructModel(); setTimeout(function () { $.ajax({ url: '/Article/Index', type: 'POST', data: JSON.stringify({ viewModel: viewModel }), contentType: 'application/json; charset=utf-8', }) },2000); console.log(viewModel);}function constructModel(){ var articleViewModel = {}; articleViewModel.Authors = ko.toJSON(appViewModel.authors); articleViewModel.ArticleData = http://stackoverflow.com/questions/15463589/{}; articleViewModel.ArticleData.Title = $("#ArticleData_Title").text(); articleViewModel.ArticleData.CorespondingAuthor = $("#ArticleData_CorespondingAuthor").text(); articleViewModel.ArticleData.Keywords = $("#ArticleData_Keywords").text(); articleViewModel.ArticleContent = {}; articleViewModel.ArticleContent.Abstract = $("#ArticleContent_Abstract").text(); articleViewModel.ArticleContent.FullText = ArticleContent(); return articleViewModel;}\[/code\]My viewModel\[code\]public class ArticleViewModel{ public ArticleData ArticleData { get; set; } public ArticleContent ArticleContent { get; set; } public ICollection<Author> Authors { get; set; }}\[/code\]My controller action viewModel.Authors is not null but has a count of 0\[code\][HttpPost] public ActionResult Index(ArticleViewModel viewModel) { if (ModelState.IsValid) { mergeViewModelToCurrentArticle(viewModel); _documentPath = GenerateDocument(_currentArticle); return RedirectToAction("Success"); } return View(); }\[/code\]The ko array outputed from javascript\[code\]Authors: "[{"id":1,"firstName":"User first name","lastName":"user last name","email":"[email protected]","phone":"xxxxx","address":"Dunarii Nr.3","fullName":"user full name"}]"\[/code\]My Author model\[code\] public class Author{ [Key] public int Id { get; set; } public int UserId{get;set;} [StringLength(40)] [Required] [DisplayName("First Name")] public string FirstName { get; set; } [StringLength(40)] [Required] [DisplayName("Last Name")] public string LastName { get; set; } [StringLength(40)] [Required] [DisplayName("E-mail")] [DataType(DataType.EmailAddress)] public string Email { get; set; } [DisplayName("Phone Number")] [Required] [DataType(DataType.PhoneNumber)] public string Phone { get; set; } [DisplayName("Address")] [StringLength(200)] public string Address { get; set; } public static implicit operator ArticleGenerator.Author(Author author) { var generatorAuthor = new ArticleGenerator.Author(); generatorAuthor.Address = author.Address; generatorAuthor.Email = author.Email; generatorAuthor.FirstName = author.FirstName; generatorAuthor.LastName = author.LastName; generatorAuthor.Telephone = author.Phone; return generatorAuthor; }}\[/code\]
 
Back
Top