首页 > 解决方案 > 试图获得正确的 url 输出

问题描述

我对带有 jquery、razor、javascript 和 html 的 asp.net mvc 网站有点陌生。现在我的操作链接有一个问题,我无法将过滤器部分插入 ..page/?sortMethod=StartDate

filters?=pending 从按钮生成(pending 只是众多状态中的一种)

?sortMethod=StartDate 从 actionlink 生成。

我试图让它们一起工作以获得:..page/?filters?=pending&sortMethod=StartDate

我试图做一个试图替换的脚本

This is the initial code, sortMethod is a string.

   <script>
        $(function () {
            $("#filterUidClear").click(function () {
                $("#filterUid").val('');
            });
            $('#filterPending').checkboxradio();
            $('#filterDirect').checkboxradio();
            $('#ApplyFilter').click(function () {

                var params = "";
                if ($('#filterPending')[0].checked) {
                    params = "filters=pending";
                }
                if ($('#filterDirect')[0].checked) {
                    if (params !== "") {
                        params = params + "&";
                    }
                    params = params + "filters=direct";
                }
                $("#param").val("?" + params);
                window.location.href = "?" + params;
            });
        });
    </script>

@Html.ActionLink("Leave Date", "Index", new { sortMethod = ViewBag.StartDate })
This is the new modified one
@Html.ActionLink("Leave Date", "Index", new { sortMethod = ViewBag.StartDate }, new { id = action })
<script>
  $(function() {
      $('#action').click(function() {
          var filterparam = $("#param").val();
          this.href = this.href + '?filters=' + encodeURIComponent(filterparam) + '&sortMethod=' + @ViewBag.StartDate;

    });
</script>

我试图让它们一起工作以获得: ..page/?filters=pending&sortMethod=StartDate 但无济于事。该表将显示已过滤的待处理结果并按日期排序

现在它显示 ..page/?action&sortingMethod=StartDate 表格显示按日期排序但没有过滤器并且操作没有被过滤器类型替换,例如 ?filters=pending

标签: javascriptjqueryasp.net-mvcrazor

解决方案


推荐阅读