1. add data-bind attribution to your dropdown

     @Html.DropDownListFor(m => m.SelectCafeBuildVersion, Model.AutoDaploymentData.CafeBuildVersions, "", 
new
 { @class = "", @data_bind = "options: cafeBuildVersions,optionsText: 'Text',optionsValue:'Value'" })       
Notce here is "@data_bind", it will change to "data-bind" in the HTML automatictly.


2. in the ajax Call get json object from backend, and add a a viewmode:

             $.ajax({
                type: "post",
                url: "MyController/RefreshModelData",
                success: function (model) {                   
                 var   viewModel = {
                        cafeBuildVersions: ko.observableArray(model.AutoDaploymentData.CafeBuildVersions)
                      )
                    };
                  ko.applyBindings(viewModel);
                
                },
                error: function (v) {
                    alert("data error!");
                   
                }
            });

That's it..

if not in ajax..you can get the modeldata from model do it in the View:
var modelData = @Html.Raw(Json.Encode(Model));
or
<script type="text/javascript">
    var initialData = <%= new JavaScriptSerializer().Serialize(Model) %>;
</script>


 
Comments are closed.