asp.net mvc 4 - Radio button not showing as checked -
i'm using knockout mvc 4. cshtml is:
... <span>@html.radiobuttonfor(m => m.isactive, true, new { @class = "statusradiobutton", data_bind = "checked: isactive" })</span> <span>@html.radiobuttonfor(m => m.isactive, false, new { @class = "statusradiobutton", data_bind = "checked: isactive" })</span> ...
my ko:
... self.isactive = ko.observable(product.isactive); ...
it updates database correctly, doesn't show radio button checked when page loaded. tried using checked = "checked" html attribute , doesn't work either. advice?
is product.isactive observable? if need execute observable product.isactive()
by initialising self.isactive = ko.observable(product.isactive());
going set once.
try turning observable like:
self.isactive = ko.computed(function() { return product.isactive(); });
edit: try changing radio buttons this:
<span>@html.radiobuttonfor(m => m.isactive, true, new { @class = "statusradiobutton", data_bind = "checked: isactive", value="true" })</span> <span>@html.radiobuttonfor(m => m.isactive, false, new { @class = "statusradiobutton", data_bind = "checked: isactive", value="false" })</span>
and writing observable use boolean value in isactive string.
self.isactive = ko.computed(function() { return product.isactive.tostring(); });
Comments
Post a Comment