【发布时间】:2017-09-08 10:36:06
【问题描述】:
我有一个带有“忘记密码”链接的登录表单。 在登录提交时,我正在调用一些其他操作,而在“忘记密码”链接上我正在调用一些不同的操作:
@Html.ActionLink("Forgot Password", "ForgotPassword", "Login", Model , new { @onclick = "return ValidateUsername();" })
我需要将它作为 POST 而不是 GET 发送。
我拥有的是一个 ASP.NET WebForm 解决方案,我几乎完全转换为 ASP.NET MVC。我在一个地方使用 LinkButton。这是唯一的瓶颈。
编辑:
现在我正在使用以下 JavaScript
$("a.anchor").click(function (e) {
e.preventDefault(); // This will stop default behavior
var validate = ValidateUsername();
if (validate) {
//alert(document.getElementById('usernameTextBox').value);
var str = document.getElementById('usernameTextBox').value;
$.ajax({
type: "POST",
url: "http://localhost/SSOMVC/Generic/ForgotPassword",
data: "data",
dataType: "text",
success: function (resultData) {
document.getElementById("usererror").textContent = resultData;
},
failure: function (error) {
}
});
}
});
@Html.ActionLink("Forgot Password", null, null, Model, new { @class = "anchor" })
public class GenericController : Controller
{
[HttpPost]
public ActionResult ForgotPassword(string data)
{
....
return Content(callResponse);
}
}
不知道为什么我总是在控制器中获取 null 数据。
【问题讨论】:
-
我认为你甚至不能用 actionlink 做到这一点;如果可以的话,它会在其中一个重载中
-
你可以阅读这个主题:stackoverflow.com/questions/2048778/…
-
问题是不清楚'Model'你可以直接在ActionLink中传入Model
-
模型没有通过动作,这就是我通过它的原因
-
你需要一个
<form>来发帖
标签: c# asp.net-mvc asp.net-mvc-5 .net-4.6