Reputation: 1282
I have a problem When clicking link( tag).it contains data-bind,by using attr binding i am giving the url,and at the same time using click binding My problem is click binding is working but not redirect the url by attr binding . I try this code..
viewModel.printbill = function () {
var dta = ko.utils.arrayFilter(viewModel.Bills(), function (item) {
return item.BillID == viewModel.BillID();
});
if (dta != null) {
var data = {
List: dta
}
localStorage.setItem('SelectedBill', JSON.stringify(data));
}
};
<a target="_blank" title="" data-bind='attr: {href:"@Href("~/billing/BillPrint") "},click:printbill'>
when clicking this link
i have a click binding:printBill,which is used to select a specific id from the button clik and map into localstorage ...all things are going good..but ..i cant redirect the screen to another tab.
Upvotes: 0
Views: 1347
Reputation: 136074
If you have both a click
binding and an href on a link then you need to return true from the binding for the href to be followed - think of it as being able to cancel the click (and therefore the navigation).
viewModel.printbill = function () {
var dta = ko.utils.arrayFilter(viewModel.Bills(), function (item) {
return item.BillID == viewModel.BillID();
});
if (dta != null) {
var data = {
List: dta
}
localStorage.setItem('SelectedBill', JSON.stringify(data));
}
return true; // <---- here
};
Upvotes: 3