1

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

6
  • if the success block of jQuery didnt execute , then the ajax call has failed. check from your c# code, whether your returning the proper response or not Commented Jul 10, 2013 at 11:44
  • public ActionResult StaffCheckAvailabilty(M and $.ajax({ url: '/Home/StaffCheckAvailabilty?Staffname=' + ds, dont you think there is a difference in the url and the ActionResult? Commented Jul 10, 2013 at 11:47
  • i m getting Values while in breakpoint please help @dreamweiver Commented Jul 10, 2013 at 13:38
  • I dont Know how to display it Commented Jul 10, 2013 at 13:39
  • you mean , your getting values at the server side(c# code side) once the ajax request is made ? Commented Jul 10, 2013 at 13:40

4 Answers 4

2

You should alert rtbs instead message

Sign up to request clarification or add additional context in comments.

Comments

0
success: function (rtbs) {
alert (message); 
$("#txtPassword").get(0).value = rtbs[0].value;
}
i think your returning rtbs array(); 

use this alert(rtbs[1]);

Comments

0

alert (rtbs);

Instedof,

 alert (message);

Comments

0

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.