Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new in MVC,I have created forgot password screen,
I want to fetch EmailId from Username entered in Username textbox by user.

But i am getting error Javascript runtime error Json is undefined

What I have tried:

<script src="/Scripts/json2.js"></script>
<script src="/Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#UserName").change(function () {
            $.ajax({
                Type:"GET/POST",
                ContentType:"application/json;charset=utf-8",
                url:'/Login/GetEmail?UserId=0&IsEnabled=False&RoleId=0&Status=False',
                data:{allData : Json.Stringify(Model)},
                dataType:"json",
                success: function(data){
                    //alert(data.property1 + data.property2 );
                    if (data == null) {
                        alert('User Id not available')
                    }
                    else if (data.EmailId == null || data.EmailId == "") {
                        alert('Email Id not available');
                    }
                    else {
                        $("#EmailId").val("");
                    }
                },
                error: function(){
                    alert("Error");
                }
            });
        });
    });
</script>


Action in controller
public User GetEmail(User u)
{
    List<User> uList = gc.Users.Include(p => p.Role).Where(p => p.UserName == u.UserName).ToList();
    return u;
}
Posted
Updated 22-Nov-17 0:01am

1 solution

use "JSON", it is case-sensitive.

JSON.stringify(Model)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900