Durandal navigate to a view with model as parameter

80 Views Asked by At

I want to navigate to a view html file (from another view's js file) but pass in the model to be used by that view. How can I do this please.

I can generally do this when I am opening the new view in a dialog. In this case, I create the model object (var model = require('viewmodels/modeljsfile), and then creating an instance of this model and accessing the properties (var instance = new model(); instance.property1 = 'Test). I then pass this instance to my modal.

Instead of opening in view html in a modal, I want to redirect to the actual view. How can I do this please?

1

There are 1 best solutions below

1
Garry Taylor On

In the view add a Compose and state the target view/model. Note that both the View/Model can be variables from the parent view.

Be careful however as not all the life cycle events are attached (activator.js)

<div data-bind="compose: { model:someModelProperty, view:someViewProperty }"/>

http://durandaljs.com/documentation/Using-Composition.html