Results 1 to 3 of 3

Thread: Geting Value to Jquery's post method's Data in MVC

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Unhappy Geting Value to Jquery's post method's Data in MVC

    I have the following Jquery in my View to check whether the Entered Username is existing or not
    Code:
    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
                $("#btnCreate").click(function () {
                    //debugger;                
                    var name = $("#UserName").val(); //Value entered in the text box
                    var status = $("#divStatus"); //DIV object to display the status message
                    status.html("Checking....") //While our Thread works, we will show some message to indicate the progress        
                    //jQuery AJAX Post request                                
                    $.post("/UserMaintenance/UserCreate", { UserName: name },
                        function (data) {                                                
                            if (data == "true") {
                                status.html(name + " is available!");
                            } else {
                                status.html(name + " is not available!");
                            }
                        });
                });
            });
            </script>
    and the following in Controller
    Code:
    if (user.UserName != null)
                    {
                        return RedirectToAction("UserList");
                    }
                    else
                    {
                        return Json(false);
                    }
    but in View the value of Data is showin Undefined and its showing the message "Username is not available" for even new Usernames.
    From the controller the value is not passing to the View.
    Anybody know how to get the value for Data in jquery's post function....help me pleaseee..

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Geting Value to Jquery's post method's Data in MVC

    Can you show the full UserCreate method?

    I would take a look at using http://fiddler (Or the proxy of your choice) to inspect what's happening on that method call.
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Geting Value to Jquery's post method's Data in MVC

    [HttpPost]
    public ActionResult UserCreate(Users user)
    {
    if (ModelState.IsValid)
    {
    userMaintenance.CreateUser(user);
    ViewBag.Flag = false;
    if (user.UserName != null)
    {
    return RedirectToAction("UserList");
    }
    else
    {

    return Json(false);
    }
    }
    return View();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width