C# .NET - MVC 4 C#: Json ajax Call issue to controller from View

Asked By A S on 13-Feb-14 09:13 PM
My method does not go to success block inside the javascript method. can anybody tell what I am doing wrong?

FYI, I tested business layer and it returns properly.

Here is my code below:


<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>


<script type="text/javascript">
    $(document).ready(function () {

$.ajax({
            type: 'GET',
            url: '@Url.Action("myActionName", "Notice")',
            data: { Name: $("#txtQueryString").val() },
            dataType: 'json',
            cache: false,
            success: function (result) {
        
                var tr;
                for (var i = 0; i < result.length; i++) {
                    tr = $('<tr>');
                    tr.append("<td>" + result[i].Month + "</td>");

                    tr.append("<td class='currency'>" + result[i].Total1 + "</td>");
                    tr.append("<td class='currency'>" + result[i].Total2 + "</td>");
                    tr.append("<td class='currency'>" + result[i].Total3 + "</td>");

                    tr.append("</tr>'");
                    tr.appendTo('#homeTable1');
                }
            }
        });

           


      
           }
});
</script>

Notice Controller========================
public JsonResult myActionName(string Name)
        {
some filled object
return Json(result, JsonRequestBehavior.AllowGet);

}
Robbe Morris replied to A S on 13-Feb-14 09:14 PM
Doesn't this have to be "name" instead of name?

 data: { "Name": $("#txtQueryString").val() },

And, you'll also want to make sure that "result" isn't null before you attempt to access/use it.