I have a simple form, which is basically my ViewModel. I'm doing a post via AJAX passing this form, but on the server side, everything is always null. My AJAX is as follows:
var formData = $('form').serialize();
$.ajax({
url: '/configuracaocomercial/Create',
type: "post",
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data: { viewModel: formData },
success: function (data) {
// meu callback
}
});
I had read in a question in the SO in English, that the problem could be the contentType, so I put this 'application/x-www-form-urlencoded; charset=UTF-8'
. However, my problem persists. On the server side, I get it simply:
[HttpPost]
public ResultadoAjax Create(ConfiguracaoComercialViewModelEdit viewModel)
{
// Aqui, a viewModel já vem null
// meu código
// ...
return result;
}