如何附加JQuery来路由Action Link上的值?

时间:2015-10-12 15:07:03

标签: jquery html razor

目前我有一个动作链接,可以将数据提交给某个动作。它还调用一个函数,该函数根据视图上的数据填充一些JQuery参数。我想将这些JQuery值附加到操作链接,以便它们可以同时提交。

查看:

 <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>

我需要将AmountFrom,AmountTo和AllDDValues附加到操作链接。

1 个答案:

答案 0 :(得分:2)

在服务器完成后,操作链接将变为<a>。 Jquery将在客户端上发生,该客户端已转换为<a>

然后你可以这样做:

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

这应该将您要查找的值附加到URL,然后在点击时将其发布到服务器。