knockout.js - How to data-bind with Razor and Knockout -
i'm trying set knockout-bound function's parameter razor. i've tried...
<a href="#" data-bind="click: function() { return myfunc(@type.sometype.tostring()); }"> click me </a> and..
<a href="#" data-bind="click: function() { return myfunc(@html.raw(type.sometype.tostring())); }"> click me </a> and..
<a href="#" data-bind="click: function() { return myfunc('@html.raw(type.sometype.tostring())'); }"> click me </a> and..
<a href="#" data-bind="click: function() { return myfunc('@(html.raw(type.sometype.tostring()))'); }"> click me </a> is there right way this?
(background: use in bootstrap dropdown)
you can try surround data-bind attribute single quotes (') , pass parameter using json.encode.
full example:
@{ // string lot of special characters string mystr = "abc\"\\/'#{}@.:xyz"; } <span data-bind='click: function() { myfunc(@json.encode(mystr)); }'> click me </span> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-debug.js"></script> <script> ko.applybindings({ myfunc: function (myparam) { console.log(myparam); } }); </script> in case be:
<a href="#" data-bind='click: function() { return myfunc(@json.encode(type.sometype.tostring())); }'> click me </a>
Comments
Post a Comment