@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>How to pass multiple parameters from ajax to mvc controller - Aspsolution.net</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js"></script>
<script>
$(document).ready(function () {
$("#btnSend").click(function () {
var Stock = { stockId: $("#stockId").val(), StockName: $("#StockName").val(), StockPrice: $("#StockPrice").val() };
$.ajax({
type: "POST",
url: '@Url.Action("GetJsonData", "Stock")',
dataType: "json",
data: JSON.stringify({ Stock }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.stockId + "-" + data.StockName + "-"+ data.StockPrice);
}
});
});
});
</script>
</head>
<body>
<p>
StockId :<input class="form-control" type="text" placeholder="Id" id="stockId">
<br />
StockName : <input class="form-control" type="text" placeholder="Name" id="StockName">
<br>
StockPrice : <input class="form-control" type="number" placeholder="StockPrice" id="StockPrice">
<br>
</p>
<br />
<input type="button" id="btnSend" name="Send" value="Send" />
</body>
</html>