Good day. I can not cope with the puzzle in MVC. There are four lists and they need to be linked. That is, by selecting something in the first list, we form a second one and so on. Scheme "Country-city-district-street". Used the scheme in ajax request and partial views. We carry out a bunch of the first two lists, but as soon as the second list is formed, and choosing from it something the third list does not form.
$('#state').change(function() { // получаем выбранный id var id = $(this).val(); $.ajax({ type: 'GET', url: '@Url.Action("GetItems44")/' + id, success: function (data) { // заменяем содержимое присланным частичным представлением $('#city').replaceWith(data); } }); }); $('#city').change(function () { var id = $(this).val(); $.ajax({ type: 'GET', url: '@Url.Action("GetItemsTopic")/' + id, success: function (data) { $('#punkt').replaceWith(data); } }); }); $('#punkt').change(function () { var id = $(this).val(); $.ajax({ type: 'GET', url: '@Url.Action("GetItemsTopic2")/' + id, success: function (data) { $('#street').replaceWith(data); } }); }); It gets into the first get, and the second no longer.
The .replaceWith() method removes all data and event handlers associated with the removed nodes.This is where the dog rummaged. - Yaant$('#city').replaceWith(data);The previously installedonchangeeventonchangecleared. Accordingly, one must either use some other way of filling the necessary element with the received data, or install the handler immediately after callingreplaceWith()- Yaant