0
votes

I have a MVC view which contains observables and observablearrays. What is the proper way to map?

My MVC ViewModel looks similar to this:

public class CategorysEditViewModel
{
    public Category Categorys { get; set; }
    public IEnumerable<Expert> candidates { get; set; }
    public IEnumerable<Expert> experts { get; set; }
}


public class Category
{
    public int CategoryID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Policy { get; set; }
}

public class Expert
{
    public int ExpertID { get; set; }
    public int CategoryID { get; set; }
    public string Name { get; set; }
    public string ExpertGUID { get; set; }
}
1

1 Answers

2
votes

Assuming the cshtml file is strongly typed to the CategorysEditViewModel, you can serialize the view model object to JSON and then use the ko.mapping tool to map it to a knockout viewmodel.

Check out this post: Best practice on passing Mvc Model to KnockoutJS