我在我的用戶可以更改自己的密碼,到一個新的,需要2個變量的方法未定義的變量,一個是新的密碼和其他的東西password.The重複是當我調用方法時,它返回字符串「未定義」,並使用該字符串作爲新密碼,將其保存在數據庫。 有人能告訴我我做錯了什麼嗎? 控制器:從阿賈克斯發送到MVC控制器
[HttpPost]
public JsonResult ChangePwdEnt(string pwd, string repeatpwd)
{
if (pwd == null || repeatpwd == null)
{
ViewBag.Error = "Insira os campos obrigatórios";
}
else
{
if (pwd == repeatpwd)
{
changePwd_Entidades(Session["ID"].ToString(),pwd);
return Json(true,JsonRequestBehavior.DenyGet);
}
else
{
ViewBag.Error = "As palavras chave precisam de ser iguais";
}
}
return Json(false, JsonRequestBehavior.DenyGet);
}
腳本:
<script>
$('.alt-btn').on('click', function() {
$.ajax({
type: 'POST',
contentType: 'application/json',
url: '@Url.Action("ChangePwdEnt", "Home")?pwd=' +
$('#Info_pwd').val() + '&repeatpwd=' + $('#Info_repeatpwd').val(),
error: function (e) {
console.log(e);
},
success: function (Changed) {
if (Changed) {
window.location = "Entidades";
} else if (!Changed) {
window.location = "LoginEntidades";
}
}
});
});
您確定您使用的HTML字段的ID是正確的嗎? – crazyglasses
@crazyglasses上帝我很盲目...使用了錯誤的模型:c非常感謝你幫助我的愚蠢嘿嘿 – Wood
哈哈沒問題 – crazyglasses