Best practice on passing Mvc Model to KnockoutJS

后端 未结 8 955
独厮守ぢ
独厮守ぢ 2020-12-04 17:12

I googled around on how to pass mvc model to knockoutjs and it seems there are two ways:

  • Using @Html.Raw(Json.Encode(Model))
  • Using $.get or $.ajax
8条回答
  •  执笔经年
    2020-12-04 17:34

    What i do is a Html.Raw and then that js object i pass it to my knockout js model. Something like this:

    //I'm using Newtonsoft library to serialize the objects
    @{
        var jsModel = Newtonsoft.Json.JsonConvert.SerializeObject(Model);
    }
    
    
    

    That's what i do.

提交回复
热议问题