I have a view model in a ASP.Net application set up right now to handle some data binding and it interacts with a Razor template on my main view that is shared across several pages. I have a select box in the Razor template that has a data binding on my current view model, but I would have to duplicate this code across several view models to gain the same functionality and I want to just have this part of my view model be abstracted just like my template is an abstraction of the part of the view it is on. Ideally what I want is something like the following (psuedo-code):
class ViewModel1{
function doSomeAjaxStuff(option from select){
}
function doSomethingOnSelectorChange(option from select){
call doSomeAjaxStuff(option from select);
}
}
class SelectorViewModel{
function getSelectorValuesFromAjax(){
//this function will populate the selectors values from an ajax call
}
function sendMessageThatSelectorHasChanged(){
//this will send to the first viewmodel that the selector value has changed
}
}
I am a bit new to the MVVM architecture and I'm not exactly sure how to do this with knockout. Can someone help me out?