0
我點擊了按鈕,但參數沒有傳遞給我的視圖。按鈕將正常工作,我只是把它放在警報消息上將顯示警報消息。 我作爲視圖follws按鈕單擊參數不傳遞給控制器
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.20.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#AddToCard').click(function() {
var ProductID = $('#txtproductID').val();
var Quantity = $('#txtQuantity').val();
var NetAmt = $('#txtNetAmt').val();
var ProName = $('#txtPN').val();
alert("ID="+ProductID+"QTY=" + Quantity+"NETAMT=" + NetAmt+"Name=" + ProName);
$.ajax({
type: "POST",
url: '../Home/AddOrderItem',
data: { productCode: ProductID, quantity: Quantity, NAMT: NetAmt, PName: ProName },
success: function (data) {
if (data) {
// alert("Added To your Card");
}
}
});
});
});
</script>
我cotroller是
public void AddOrderItem(Int64 productCode, int quantity, decimal NAMT, string PName)
{
//adds an item to the current order
OrderDO order = (OrderDO)Session["Order"];
decimal TotAmt = quantity * NAMT;
order.Items.Add(new OrderItem(productCode, quantity,NAMT,PName,TotAmt));
Session["Order"] = order;
}
你沒有從AddOrderItem返回任何東西,如何調用成功?什麼是你想傳遞的參數? – 2013-02-11 08:47:00
我申請下面的代碼,之後,ajax函數不能工作public ActionResult AddOrderItem(Int64 productCode,int quantity,decimal NAMT,string PName) { //將項目添加到當前訂單 OrderDO order = (OrderDO)會話[ 「訂單」]; decimal TotAmt = quantity * NAMT; Order.Items.Add(new OrderItem(productCode,quantity,NAMT,PName,TotAmt)); order.Items.Add Session [「Order」] = order; return Json(order,JsonRequestBehavior.AllowGet); } – Raja 2013-02-11 09:42:01