jquery - How to set a knockout property with a MVC model view property in a partial view -
i have next scenario:
im working knockout (ver 2.1.0) , asp mvc.net, in 1 specific point controller calls new view. view renders partial view next call:
<div id="productseriesnonsocks"> @{ html.renderpartial("~/views/salesordermanagement/getavailableproductseriesnonsocks.cshtml", model); } </div> the controller called view viewmodel (model) few properties, above call sends whole model partial view.
in partial view can access model properties simple sentence this:
available season type: @model.seasontype the problem starts here... partial view has own knockout model:
<script type="text/javascript"> $(function () { //activates ko ko.applybindings(productseriesnonsocksmodel); getdatafrommodels(); }); var productseriesnonsocksmodel = { availableproductseriesnonsocks: ko.observablearray([]), selectedprodseries: ko.observable(), seasontype: ko.observable() }; function getdatafrommodels() { $.get('/salesordermanagement/getavailableproductseriesnonsocks', { seasontype: this.seasontype() }, function (data) { productseriesnonsocksmodel.availableproductseriesnonsocks(data.availableproductseriesnonsocks); }); } </script> the getdatafrommodels() function should call method in controller seasontype parameter in order retrieve proper array , put on availableproductseriesnonsocks array. problem here don't know how pass value property model (in case @model.seasontype) knockout model call function in controller (productseriesnonsocksmodel.seasontype).
i tried pass value with:
seasontype: ko.observable(@model.seasontype) or
seasontype: @model.seasontype but doesn't work. idea pass model property value knockout property value in order make call $.get(...)?
to clarify, can't ask value because value (seasontype) choosen user in previous view.
thank in advance.
you can use razor in script tags.
<script type="text/javascript"> var seasontype = @model.seasontype; // season type </script> it might make sense avoid additional request. put data "/salesordermanagement/getavailableproductseriesnonsocks" in model or viewbag , render javascript object.
Comments
Post a Comment