0

I have a model like this in Asp.Net Mvc:

 public class CustomerModel : BaseModel
    {
        public CustomerModel()
        {

            Vats = new List<Vat>();
            SelectedVat = new List<long>();
            AdressItems = new List<AddressModel>();
            CustomerTypes = new List<CustomerType>();
            CustomerType = new List<long>();
            Factory = new Factory();
            Company = new Company();
            Branch = new BranchModel();

            Transporter = new TransporterModel();
            Cities = new List<City>();
            SelectedCity = new List<long>();

            SelectedWareHouse = new WareHouseModel();
            WareHouses = new List<WareHouseModel>();
            SelectedAddress = new AddressModel();
            Addresses = new List<AddressModel>();

        }

        public long Id { get; set; }

        public string Title { get; set; }

        public string SignBoard { get; set; }



        public long? VatId { get; set; }

        public bool IsHasWarehouse { get; set; }
        public bool IsManifacturer { get; set; }
        public bool Valid { get; set; }

        public List<AddressModel> AdressItems { get; set; }


        public List<CustomerType> CustomerTypes { get; set; }
        public List<long> CustomerType { get; set; }

        public Factory Factory { get; set; }
        public Company Company { get; set; }

        public BranchModel Branch{ get; set; }
        public TransporterModel Transporter { get; set; }


        public List<Vat> Vats { get; set; }
        public List<long> SelectedVat { get; set; }


        public List<City> Cities { get; set; }
        public List<long> SelectedCity { get; set; }


        public List<WareHouseModel> WareHouses { get; set; }
        public WareHouseModel SelectedWareHouse { get; set; }

        public List<AddressModel> Addresses { get; set; }
        public AddressModel SelectedAddress { get; set; }

    }

I send it to my view and mapp it to knockout js model. Then when I look the model, I see that Id, Title, Vats and SelectedCity is made observable except Factory and other object defined like it.

I searched for a long time to find the reason but i couldn't.

Does anyone have an idea about that?

Edit: viewModel before pushing to mapping is like that:

enter image description here

mavera
  • 3,171
  • 7
  • 45
  • 58
  • Can you post json viewmodel before you push it to mapping plugin as well ? – Ondrej Svejdar Aug 23 '13 at 20:42
  • I've just posted it @OndrejSvejdar – mavera Aug 23 '13 at 20:51
  • In theory inner objects should be observable as well (see my fiddle - http://jsfiddle.net/svejdo1/Xxvp3/2/). Are you sure you aren't setting anything to the viewmodel directly (this can damage the viewmodel) ? – Ondrej Svejdar Aug 23 '13 at 21:17
  • You need to map your navigation properties as observables. It is a very well documented thing and if easy to find on here. Without your view model no one is going to be able to diagnose your problem. – PW Kad Aug 23 '13 at 23:24
  • @PWKad the link you sent helped me. Thanks. – mavera Aug 24 '13 at 08:58

0 Answers0