目前我正在处理 MVC 应用程序,因为我需要将页面呈现给 MVC 应用程序中的另一个操作,因为我需要将 Id 参数传递给该操作。
这是我的代码。
var CardCode=$('#CardCode').val();
if (str.substr("successfully")) {
window.location.href='@Url.Action("EditPartner","MstPartner",new { id = CardCode})';
}
在该代码中,当我将值传递给该 id 时,即那里不允许的 id=CardCode
那么如何将 CardCode 值传递给该操作?
请提出一些建议。
最佳答案
您的代码不起作用,因为您不能在其中传递变量。它仅在值被硬编码时才有效
window.location.href='@Url.Action("EditPartner","MstPartner",new { id = "123"})';
你可以做的是使用Replace
方法
var CardCode=$('#CardCode').val();
if (str.substr("successfully")) {
window.location.href='@Url.Action("EditPartner","MstPartner",new { id = "CC"})'.replace("CC",CardCode);
}
关于javascript - 如何在 MVC 应用程序中将 Id 值传递给 window.location.href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39200159/