如果有任何帮助,我将不胜感激。
我每次都尝试使用 Kendo Grid change()
事件更改链接 href
:
function ContractsGrid_onChange(e) {
var selected = this.select()[0],
item = this.dataItem(selected);
$('#createOnBase').attr('href', function () {
var createLink = document.getElementById("createOnBase");
var route = 'http://' + createLink.hostname + createLink.pathname + "?contractID =" + item.ID;
return route;
});
}
@Ajax.ActionLink("Create", "CreateOnBase",
new { contractID = "_contractID_" },
new AjaxOptions() {... },
new { id="createOnBase" })
我不确定当前的方法,因为我有不同的主机名(带有端口或服务器域的本地主机)
最好的方法是:
var route = "@Url.Action('CreateOnBase', new { contractID = ??})";
但我不能在 razor 中使用 JS 变量 (item.ID
)。
此外,this.href.replace("_contractID_", item.ID)
将无法进行多项更改。
你能帮我解决另一个问题吗?
非常感谢!
最佳答案
是的,这很简单,我找到了一个方法:
$('#createOnBase').attr('href', function () {
return "@Url.Action("CreateOnBase")"+ "/?contractID=" +item.ID;
});
也许这对某人有帮助。
关于javascript - 使用 jQuery 更改链接的路由值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26970713/