I am posting id of a vehicle to controller from jquery ajax post.Ajax call is calling controller method but that string is always null.I searched a lot on web but any solution is not working.id has value in view but null in controller.please help me.
here is my code: View
<script type="text/javascript">
function DeleteVehicle(id) {
alert("working");
if (confirm("Do you want to delete vehicle: " + id)) {
// var requestData = { 'vehicleId': vid }
var dataPost={'id':id}
$.ajax({
url: '@Url.Action("DeleteVehicle", "Vehicle")',
type: 'POST',
data: dataPost,
success: function (data) {
alert("Success, sent data to controller");
},
error: function (data) {
alert("Error: " + data.responseText);
}
});
}
}
$(function () {//when the document is ready
$("#Delete").click(DeleteVehicle);
});
controller
public ActionResult DeleteVehicle(string id)
{
//code
return Json(id, JsonRequestBehavior.AllowGet);
}