Hi,
I have successfully implemented two multiselect list. List1 contains states and List2 contains counties. What I want to achieve is when I click on List2, it populate only with counties exist in selected states from List1.
Here is what I did;
1. Attached to open even on List2.
2. Wrote a JS function that cause datasource to update for List2 sending data. data is selected from List1.
function open() {
console.log("event: open");
var values = {
selectedStates: $("#stateMultiSelect").val()
};
var stateItem = $('#countyMultiSelect').data('kendoMultiSelect');
stateItem.dataSource.read(values);
};
The problem seems to be in model binding, I can see the request contains the data but at controller action it does not map to the model.
Controller Action:
public JsonResult GetCounties(StateMultiSelectModel seletedStates)
{
// seletedStates is alway null when breakpoint hits here.
if (selectedStates == null)
{
...
}
...
}
Model
public class StateMultiSelectModel
{
public List<string> SelectedStates { get; set; }
}
Following is the request sent to controller.
Request URL:
http://localhost:61135/Dashboard/GetCounties?text=&SelectedStates%5B%5D=NC
In the same JS file I have chart controls that are getting updated on a button click using similar mechanism.
Please suggest changes. For your reference attached cshtml file that contain UI control code and JS.
I have successfully implemented two multiselect list. List1 contains states and List2 contains counties. What I want to achieve is when I click on List2, it populate only with counties exist in selected states from List1.
Here is what I did;
1. Attached to open even on List2.
2. Wrote a JS function that cause datasource to update for List2 sending data. data is selected from List1.
function open() {
console.log("event: open");
var values = {
selectedStates: $("#stateMultiSelect").val()
};
var stateItem = $('#countyMultiSelect').data('kendoMultiSelect');
stateItem.dataSource.read(values);
};
The problem seems to be in model binding, I can see the request contains the data but at controller action it does not map to the model.
Controller Action:
public JsonResult GetCounties(StateMultiSelectModel seletedStates)
{
// seletedStates is alway null when breakpoint hits here.
if (selectedStates == null)
{
...
}
...
}
Model
public class StateMultiSelectModel
{
public List<string> SelectedStates { get; set; }
}
Following is the request sent to controller.
Request URL:
http://localhost:61135/Dashboard/GetCounties?text=&SelectedStates%5B%5D=NC
In the same JS file I have chart controls that are getting updated on a button click using similar mechanism.
Please suggest changes. For your reference attached cshtml file that contain UI control code and JS.