1

At the moment I have an action link which submits data to an action. It also calls a function which populated some JQuery parameters based on data on the view. I would like to append these JQuery values to the action link so they can get submitted at the same time.

View:

 <div class="AltFunctions">
                    <ul>
                        <li>
                            @Html.ActionLink("fd", "ExportClaimBySupplier", "Search", new {ClientID = Model.inputParameters[0], SupplierID = Model.inputParameters[1], JsonReviewPeriod = Json.Encode(Model.inputReviewPeriodIDs), GroupID = Model.inputParameters[2], AmountFrom = JQueryValue, AmountTo = JQueryValue, AllDDValues = JQueryValue}, new { @id = "altExportButton", @class = "AltButton", Title = " Export data to excel" })
                        </li>
                        <li>
                            <a href="#ClaimsBySupplierModal" data-target="#ClaimsBySupplierModal" data-toggle="modal" class="AltButton" id="altInfoButton" title="Information on the Supplier report">Info</a>
                        </li>
                    </ul>
                </div>

JQuery:

<script>
  $('#altExportButton').on('click', function () {
            var AmountFrom = $('#txtAmountFrom').val();
            var AmountTo = $('#txtAmountTo').val();
            var AllDDValues;
            var count = 1;
            $('.ExportValues').each(function () {

                if (count == 1) {
                    AllDDValues = this.value;
                    count = 2;
                }
                else if(count == 2 && AllDDValues != "") {
                    AllDDValues = AllDDValues + ", " + this.value;
                }
            });            
        });

    </script>

I would need to append AmountFrom, AmountTo and AllDDValues to the action link.

1 Answer 1

2

Action links just become <a> after the server is done with it. Jquery will happen on the client which is after it has transformed into a <a>.

Then you can do something like this:

$('#altExportButton').attr('href', function(index, attr) {
return attr + '&AllDDValues=' + AllDDValues + '&AmountTo =' + AmountTo +'&AmountFrom=' + AmountFrom;
}); 

This should append the values you're looking for to the URL which then should post them to the server on click.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.