javascript - 试图获得正确的 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
解决方案
推荐阅读
- swift - 领域是否需要显式添加嵌套对象
- python - 仅使用 Twitter 流 API 显示来自单个用户的推文
- vaadin - 用于 netBeans 上下文菜单的 Vaadin javadoc
- python - 从hipages中提取到
- r - 缩放热图上的geom_point大小以正确适合R?
- android - 如何在自定义对话框片段中使用点击监听器?
- python - 获取列表列表的四分位数,并绘制它们
- javascript - 使用对象对数组进行操作
- c++ - 如果我希望它按对象而不是指针排序,那么声明一组 std::unique_ptr 的好方法?
- node.js - 更改页面时会话丢失,Passport.js