Я пытаюсь передать «обычный» тип параметров из вызова ajax ($ .post) из представления в контроллер, который должен получить эти параметры плюс список>.
Мне нужна причина этого спискаэти параметры будут отличаться от model.types, а метод в контроллере отправит все параметры в случае переключения на частные методы.
Я пробовал несколько сборок объектов jquery, JSON.stringify, массив с индексами встрока (я знаю, что не могу назвать столбцы явно ... часть моего вопроса), которая всегда заканчивается списком> нулю в методе бэкэнда.
Параметры 'params' видны в отладке xhr, но параметр _options всегда равен null (метод ref controller).
Вот мои переменные и мой вызов ajax:
function initDocumentsPreviewsActions() {
$('.documents-list-preview-action').on('click', function () {
if (xhrPreviewLoad != undefined)
xhrPreviewLoad.abort();
$('#documents-preview').html('<div class="general-form-message-loader"></div>');
documentCurrentIndex = $(this).data('btnindex');
setDatatableRowActive();
var documentType = $(this).data('documenttype');
var adherentRessourceId = $(this).data('adherentressourceid');
var annee = $(this).data('annee');
var echeancier = $(this).data('echeancier');
var destinataireid = $(this).data('destinataireid');
var destinatairetypeid = $(this).data('destinatairetypeid');
var emetteurid = $(this).data('emetteurid');
var emetteurmandatid = $(this).data('emetteurmandatid');
var trimestres = $(this).data('trimestres');
var params = [
{ '_annee': '' + annee + '', '_echeancier': '' + echeancier + '', '_trimestres': '' + trimestres + '' }
];
xhrPreviewLoad = $.ajax({
url: '/Documents/PreviewDocumentSingle',
data: {
_documentType: documentType,
_adherentRessourceId: adherentRessourceId,
_annee: annee,
_destinataireId: destinataireid,
_destinataireType: destinatairetypeid,
_emetteurId: emetteurid,
_emetteurMandatId: emetteurmandatid,
_echeancier: echeancier,
_options: JSON.stringify(params)
},
dataType: 'json',
type: 'POST'
}).done(function (documentPartialView) {
$('#documents-preview').html('<img src="' + documentPartialView.src + '"/>');
xhrPreviewLoad = undefined;
});
});
}
xhd Параметры в отладчике Firefox:
_documentType AppelCotisation
_adherentRessourceId 836
_annee 2018
_destinataireId 11
_destinataireType Syndicat
_emetteurId 16289
_emetteurMandatId 5986
_echeancier False
_options [{"_annee":"2018","_echeancier":"False","_trimestres":"undefined"}]
Метод контроллера:
[HttpPost]
public JsonResult PreviewDocumentSingle(string _documentType, int _adherentRessourceId, int _destinataireId, string _destinataireType, int _emetteurId, int _emetteurMandatId, List<KeyValuePair<string, string>> _options)
{
//(_options = null)
//some code
return JsonResult
}
Я уже сделал это давным-давно, но не могу приложить руку или свой мозг к нему,Я уверен, что это мелочь.
Я ожидаю получить ВСЕ мои параметры правильно или мне предлагается объявить другой Список другого типа во внутреннем интерфейсе (и как формализовать его впереди), или Array.... ну ... любая помощь - это хорошо.
Но я бы очень хотел оставить musctor в бэкэнде как есть.