I am making ajax call to server requesting some data. for eg: http/get(SomeDataService). In controller i have data object as below:
API Controller:
public DataCollection getSomeData()
{
try{
// get the data in object and checking its null or not.
//If not null, will bind the data in ko viewModel.if null throw below exception.
}
catch(Exception e)
{
e. message(" No Data Found")
}
}
Now i want to bind the "No data found" message inside KO viewModel and view.
Please suggest me how to do this? I am new to KO, ASP.net
I am re-posting again what i need actually. 1. Making web api Ajax call
function GetData() {
var data = http.get(apiUrl)
.success(function (data) {
if (data != null )
{
// some stuff for success data
vm.getDataSuccess;
}
else {
vm.errorMessage();// server side exception message.
})
WebApi controller:
public DataCollection GetSomeData() { var data = GetData(); if( data == null ){ throw new Exception("Data is null");
}
I have created viewmodel like below:
var vm = { activate: activate, getDataSuccess: ko.observableArray(), errorMessage:ko.observable(), title: 'TopNews' };
bind on view page in one of the div
-- <-div class="error" data-bind="text: errorMessage" />
i am not sure above method is correct or not. but i need like this.