gpt4 book ai didi

javascript - 如何在 ASP .NET 中将变量从 View 传递到 Controller

转载 作者:行者123 更新时间:2023-11-30 09:59:37 25 4
gpt4 key购买 nike

我发现了与我类似的问题,但在所有这些示例中,变量都是模型的一部分。我正在尝试传递一个在 javascript 中创建的变量,它不是模型的一部分。

代码:

 $(document).ready(function () {

var url = document.URL;
var index = url.indexOf("?email=");
var email;

/* If there is an EMAIL in URL, check directory to confirm it's valid */
if (index > -1) {
/* There is an email */
email = url.substr((index + 7));
email = email.substr(0, (email.length - 4)) + "@@mymail.ca";

/* Check directory to see if this email exists */
@Html.Action("CheckDirectory", "Home", new { email = ???});

}
});

有没有办法填写???使用上面的电子邮件?

最佳答案

您可以在 Controller URL 中将您的值作为 GET 参数传递:

$(document).ready(function () {

var url = document.URL;
var index = url.indexOf("?email=");
var email;

/* If there is an EMAIL in URL, check directory to confirm it's valid */
if (index > -1) {
/* There is an email */
email = url.substr((index + 7));
email = email.substr(0, (email.length - 4)) + "@@mymail.ca";

/* Check directory to see if this email exists */
window.location.href = '/CheckDirectory/Home?email=' + email;
}
});

关于javascript - 如何在 ASP .NET 中将变量从 View 传递到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32360431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com