2
I have a simple form, which is basically my Viewmodel. I am doing a post via AJAX passing this form, however, 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 OS 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 simply get it:
[HttpPost]
public ResultadoAjax Create(ConfiguracaoComercialViewModelEdit viewModel)
{
// Aqui, a viewModel já vem null
// meu código
// ...
return result;
}
Remove viewmodel and place
data: formData
and testing– novic
@Virgilionovic worked, the problem is I have to pass another parameter to function
– Artur Trapp
@Arturotemplário until I put as answer, which parameter? that needs more???
– novic