Reputation: 2165
I'm building a simple MVC application. In my CSHTML file I'm build this code:
<script type="text/javascript">
//modify as needed to make it pass in what you need.
function GeneratePdf() {
alert(idSlot);
$.ajax({
url: "@Url.Action("saveRROriginal", "Martinenko")",
data: { idSlott:idSlot },
cache: false,
contentType: false,
processData: false,
type: "POST",
success: function (data) {
//TODO: Add whatever if you want to pass a notification back
alert("success");
},
error: function (error) {
//TODO: Add some code here for error handling or notifications
alert("no success");
}
});
}
</script>
<div class="col-md-12" style="width:100%;height:100%;margin-top:5px;">
<button onclick=GeneratePdf()>
Salva RR</button>
</div>
This is the code of void method:
public void saveRROriginal(String idSlott)
{}
Alert message print correctly the value of idSlot but in void method idSlott = null.
Upvotes: 0
Views: 295
Reputation: 98
Your json format is not valid. It should be:
{ "idSlott": "idSlot" }
Also add following lines to your request:
contentType: "application/json; charset=utf-8",
dataType: "json",
Upvotes: 1