Click here to Skip to main content
15,943,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I retrieved the discounted price via action method GetDis and display it in the view.

I want to pass the discounted price value to the other action method . so i can use it in the controller . How can i pass the value for view to the controller.

<pre>@foreach (var item in Model) {
    <tr data-productid="@item.Id">
            @Html.DisplayFor(modelItem => item.ProductName)
            @Html.DisplayFor(modelItem => item.ProductPrice, new { @id = "check" })

               @Html.DropDownList("Status", new List<SelectListItem>
                    new SelectListItem{ Text="Student Discount", Value = "1" },
                    new SelectListItem{ Text="Loyalty Discount", Value = "0" }
                 }, "Please select discount", new { @class="ddlStatus" })

            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })

<div class="clearfix">
    <div class="pull-right">
        <label>Discount: <span id="lblDiscountAmount"></span></label>

@section scripts{
        $('.ddlStatus').change(function () {
            var val = $(this).val();
            var productId = $(this).parent('td').parent('tr').attr('data-productid')
            ChangeDis(val, productId);
        function ChangeDis(val, productId) {
                url: '/Products/GetDis',
                data: {
                    discount: val,
                    productId : productId
                success: function (data) {


This discounted price value is appended on the
<label>Discount: <span id="lblDiscountAmount"></span></label>
I want to send it to the another controller in some action method. how can i do it.

What I have tried:

I have displayed the discounted price in the view . and want to pass the value of discouted price to another controller in a action method.
Updated 21-Aug-17 7:27am

1 solution

If you want to submit the value with your form, then you need to add a hidden field:
<label>Discount: <span id="lblDiscountAmount"></span></label>
<input type="hidden" name="DiscountAmount" id="DiscountAmount" />
success: function (data) {

If you want to pass it via an action link, then you'll need to identify those links, and pass the discount amount via the URL:
@Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "--js-pass-discount" }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }, new { @class = "--js-pass-discount" }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
$(document).on("click", "a.--js-pass-discount", function(e){
    var discountAmount = $('#lblDiscountAmount').text();
    if (!discountAmount) { return; }
    var url = this.href;
    var i = url.indexOf('?');
    url = url + (-1 === i ? '?' : '&') + 'discountAmount=' + encodeURIComponent(discountAmount);
    window.location.href = url;

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900