I want to put a partialview when the value of a dropdownlist changes. With my code it works but when I want to send data to the controller using post method I always have null values (the controller parameter always have null data). I have seen a lot of different ways to do it but no one works for me.
My view ajax code:
@section scripts {
<script type="text/javascript">
$("#ProjecteId").on("change", function () {
var request = JSON.stringify({
'ProjecteId': $('#ProjecteId').val()
});
console.log(request);
$.ajax({
type: 'Post',
url: '/Consultas/MostrarTipusPersona',
dataType: 'html',
contentType: 'application/json',
data: request,
success: function (data) {
console.log('sample', data);
},
error: function () {
}
});
});
</script>
}
My controller:
[HttpPost]
public IActionResult MostrarTipusPersona(ProjecteModel pm)
{
return PartialView("_Ciutada", new Ciutada());
}