want to display discounted price using onchange event of jquery in my asp.net mvc
but getting 500 internal server error.
GET http:
View code is
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductPrice, new { @id = "prisValue" })
</td>
<td>
@Html.DropDownList("Status", new List<SelectListItem>
{
new SelectListItem{ Text="Student Discount", Value = "1" },
new SelectListItem{ Text="Loyalty Discount", Value = "0" }
}, "Please select discount", new { onchange = "ChangeDis(this,'" + item.ProductName + "')" })
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
@section scripts{
<script>
function ChangeDis(o, proName, targetPrice) {
var targetPrice= $("#prisValue").val();
$.ajax({
url: '@Url.Action("GetDis")',
data: { "discount": o.value, "productName": proName , "tPrice":targetPrice},
success: function (data) {
$(targetPrice).text(data);
}
});
}
</script>
}
What I have tried:
public ActionResult Index()
{
Customers customer = new Customers();
return View(db.Products.ToList());
}
public JsonResult GetDis(string discount, string productName, decimal tPrice)
{
Customers customer = new Customers();
var products = db.Products.ToList();
decimal price;
if (discount == "1")
{
customer.SetDiscountStrategy(new LoyalStudentDiscount());
price = customer.ApplyDiscount(tPrice);
}
if (discount == "0")
{
customer.SetDiscountStrategy(new LoyaltyDiscount());
price = customer.ApplyDiscount(tPrice);
}
return Json(JsonRequestBehavior.AllowGet);
}
How to disply discounted price on a view