嗨,我正在使用 MVC 应用程序,因为我正在验证用户名以防止数据库中的重复名称。只是我需要显示消息框或其他东西
我的 JavaScript 代码:
<script type="text/javascript">
$(document).ready(function () {
$("#CheckAvailabilty").click(function () {
var ds = ($("#txtLoginname").val());
$.ajax({ url: '/Home/StaffCheckAvailabilty?Staffname=' + ds,
type: "Post",
dataType: "json",
success: function (rtbs) {
alert (message);
$("#txtPassword").get(0).value = rtbs[0].value;
}
});
});
});
</script>
C#代码:
public string rtbs;
public ActionResult StaffCheckAvailabilty(ModelGridAllFeatures model, string Staffname)
{
var query1 = DB_Linq.TblStaffPersonalDetails
.Where(s => s.LoginName == Staffname)
.Select(s => new { s.StaffName, s.ActiveFlag });
int name = query1.Count();
//var rtbs;
if (name != 0)
{
Response.Write("Login Name already Exists");
rtbs = "Login Name already Exists";
}
else
{
Response.Write("Available");
rtbs = "Available";
}
return Json(rtbs);
}
我正在恢复 rtbs 但它没有显示警报消息