Skip to content Skip to sidebar Skip to footer

Returning Json Data From Controller To View Asp.net Mvc

I am trying as the title says to return a Json message from the Controller to the View after it validates. I have made a breakpoint, and I know that the code works from Controller

Solution 1:

You are getting the value of $("#userId"), but your input has an id of idUser.

Try making your input:

<inputtype="text"id="userId"class="form-control" />

Also it would be a good idea to provide your Stamping model structure as it seems that you only pass the user id in your post and nothing else.

Solution 2:

Change your javascript code as following:

            $(document).ready(function () {

        $("#stampInBtn").click(function () {

        var userId = $("#userId").val();

            $.ajax({
                url: "ComeAndGo/CreateStamp",
                type: "POST",
                dataType: "json",
                data: {
                    userId: userId,
                },
                success: function(data) {
                var objData= jQuery.parseJSON(data);
                alert(objData.Message );
                },
                error: function (request, status, error) {
                    alert(request.responseText);
                }

            });

        });
    });

Post a Comment for "Returning Json Data From Controller To View Asp.net Mvc"