【发布时间】:2014-12-08 07:27:38
【问题描述】:
我在创建视图中使用 MVC 4 我有以下代码
@Html.TextBoxFor(model => model.USER_EMAIL, new { @class = "form-control", id="userModelEmail" })
@Html.ValidationMessageFor(model => model.USER_EMAIL)
我添加了对我的视图的引用
<script src="~/Contents/Common.js"></script>
在common.js 中,我想从TextBoxFor 中获取值。我在common.js 中添加了以下代码
$("#btnRegister").click(function () {
debugger;
var userData = {
userEmail: document.getElementById('USER_EMAIL').value(),
userPassWord: document.getElementById('userModelPwd').value(),
userConfirmPassword: document.getElementById('userModelCfmPwd').value(),
userMObile: document.getElementById('userModelMob').value(),
}
debugger;
$.ajax({
type: "POST",
url: 'Home/Register',
data: '{userDetails:' + JSON.stringify(userData) + '}',
success: function (res) {
debugger;
// alert("data is posted successfully");
if (res.success == true) {
debugger;
$('#modalLogin').modal('show');
// window.location.href = window.location.href + res.AdminLocation;
debugger;
} else {
document.getElementById("lblInvalidUser").style.display = "inline";
}
},
error: function (xhr, textStatus, errorThrown) {
alert(xhr.statusMessage);
return false;
}
});
return true;
});
但在 userEmail:document.getElementById('USER_EMAIL').value()USER_EMAIL 的行显示无法解决我也尝试使用 id
document.getElementById('userModelEmail').value() 这里也显示 id 无法解析。
如何解决?
【问题讨论】:
-
您查看过实际解析的 HTML 并且没有尝试在该元素 id/class 或唯一标识符上调用 JQ
.load()吗????类似$('#res').load( "Home/Register.html #id_of_the_thing" );
标签: jquery asp.net-mvc asp.net-mvc-4 razor