Knockoutjs afterRender doesn't start native template

Let's look at some HTML markup that uses a partial MVC view to create a dialog. When the selectedMember is set to the viewmodel, the dialog will be populated and the openDialog event will be triggered which invokes the JQuery dialog ("open").

I use the afterRender event to provide unobtrusive validation as the dialog is dynamically created. However, the afterRender function is never called?

<div id="dlgAddMember" class="hidden" data-bind="with: selectedMember, openDialog: selectedMember, afterRender:hookupValidation">
        @Html.Action(ekmMvc.People.AddMemberDialog())
</div>

      

Does anyone know why this is not working. This seems to work fine using the JQuery templating engine.

+3


source to share


1 answer


You need to specify it as:

data-bind="template: { data: selectedMember, if: selectedMember, afterRender: hookupValidation }"

      



If you do not provide a template name, it will use anonymous templates. So this is the equivalent with

with afterRender.

+5


source







All Articles