Hi, I am using MVC Application, in that I am validating user name to prevent Duplicate names from database. Just I need to show message box or somthing
My JavaScript code:
<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# code:
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);
}
I am returing rtbs but its not showing alert message
您应该提醒rtbs而不是消息
success: function (rtbs) {
alert (message);
$("#txtPassword").get(0).value = rtbs[0].value;
}
i think your returning rtbs array();
use this alert(rtbs[1]);
alert (rtbs);
Instedof,
alert (message);
The data returned is in rtbs, not message.
Try:
alert(rtbs);
If that doesn't work check you are getting to that point in the code with a simple:
alert("Success function reached");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.