shoaibshafiqahmed says:
data: JSON.stringify(prod),
You are passing only model to the ActionResult.
You need to send the qty and id aswell.
Create a class and define the property with model and use that class to pass to the ActionResult.
public class Data
{
public ProductsWidgetsViewModels Product { get; set; }
public string qty { get; set; }
public int? id { get; set; }
}
Controller
public ActionResult AddtoCartp(Data data)
{
}
JavaScript
<script type="text/javascript">
$(function () {
$("[id*=SaveBtnPro]").click(function () {
var data = {};
data.qty = "10";
data.id = 1;
var prod = {};
prod.ProductId = $('[id*=pid]').val();
prod.ProductName = $('[id*=pname]').val();
prod.Price = $('[id*=pprice]').val();
prod.Quantity = $('[id*=qty]').val();
data.Product = prod;
$.ajax({
type: 'POST',
url: '/Widgets/AddtoCartp',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
}).done(function (response) {
window.location.href = "/Home/Index";
}).fail(function (XMLHttpRequest, textStatus, errorThrown) {
alert(response.responseText);
});
});
});
</script>