I'm trying to create an HtmlHelper
extension that outputs some HTML to the view. In this HTML I'm wiring up some KnockoutJS binding. I'm new to KO so I'm still struggling in getting some things done. Anyway, what I'm trying to do is generate input fields (in the server-side code) bound to observables on my client-side code, then set the initial values of the observables through the value of the hidden fields. Unfortunately, that is not working for me. So I'm wondering if there any way I could get this done (even if I have to do it completely different).
Here's what I'm basically doing:
In my client side view model I have the following:
self.dataSource = ko.observable();
self.pageSize = ko.observable();
And my extension method outputs the following:
<input type="hidden" value="/Employee/Get" data-bind="value: dataSource" />
<input type="hidden" value="30" data-bind="value: pageSize" />
But when the page renders, when I inspect the elements I notice that the value
of the input fields is being set to an empty string, which I believe is because of the way observables are being declared. But is there a way to override this behavior or something?