바구니에 추가 된 제품의 총량을 보여주는 총 제품 페이지가 있습니다. 사용자가 할 수있는 프로모션 텍스트 필드를 추가하고 싶습니다. 할인을 받기 위해 프로모션 코드를 추가하면 프로모션 코드가 할인율로 데이터베이스에 저장됩니다. 따라서 고객이 코드를 입력하고 프로모션 버튼을 누르면 시스템은 유효한 프로모션 코드를 확인한 다음 총 가격을 할인율로 공제하여 순간 계산을 수행해야합니다. 이 작업은 jQuery Ajax를 사용하여 수행 할 수 있습니까? 아니면 다른 가능한 솔루션이 있습니까? 모든 도움말 또는 자습서를 매우 높이 평가할 것입니다. 건배mvc2의보기에서 jQuery의 Ajax를 사용하여
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#promo").change(function() {
var $this = $(this);
var number = $('promoNumber').val();
$.ajax({
url: '/Booking/Review',
type: "POST",
data: {number:textbox},
success: function (data) {
if (data["success"]) {
alert(data)
}
}
});
});
});
</script>
<%using (Html.BeginForm())
{ %>
<table>
<tr>
<td> <input type="button" id="promo" value="Promo" /> </td>
<td> <%: Html.TextBox("promoNumber") </td>
</tr>
<tr><td>
<div class="totalCost">
<label><b>Total Amount:</b></label> <%: String.Format("{0:c}", ViewBag.TotalAmount)%> <br /></div>
</td></tr>
</table> }%>
컨트롤러
[HttpPost]
public ActionResult Review(int number)//this parameter is my selected checkbox value.I have to get this value from ajax
{
IVoucherRepository voucherResp = new VoucherRepository();
IQueryable<Voucher> getVoucher = voucherResp.GetVouchers(number);
//first check if the code is there or not else return error
int discount = 0;
foreach (var number in getVoucher)
{
discount = number.discount;//Thats the discount number
}
//after getting the discount code i need to pass that to ViewBag.TotalAmount to do calculation
ViewData["Data"] = "success";
return View();
}
이것은 확실히 Javascript/AJAX로 수행 할 수 있습니다. jQuery는 좋은 출발점이 될 것이다. 또는 Knockout.js는 주로이 목표를 달성하는 데 기반을 둔 프레임 워크입니다. 먼저 프레임 워크를 선택하고 그 프레임 워크를 가지고 놀아야합니다. 보유하고있는 코드에서 관련 코드를 가지고 있습니까? – ghayes
asp.net MVC를 사용하고 있습니다 –
네,하지만 (태그에서) jQuery도 사용하고 있습니다. 근본적으로, 예, 사용자가 쿠폰 코드를 입력하면 관련 가격 할인을 반환하고 필드를 적절히 업데이트하는 AJAX 요청을 시작할 수 있습니다. 특정 질문에 대한 답변은 다른 관련 코드없이 제공 될 수 있습니다. – ghayes