MVC 3 JSON not working in IIS

I am working in an MVC 3 application with an ASPX engine, and as a starting point I developed a simple search that uses a jQuery JSON call to get some information. The call sends a parameter taken from the text input and updates the table with the results. The function looks like this:

        function PerformLookup() {
            var _accountNumber = $('#accountNumber').val();

            $.ajax({
                url: '/SearchAjax/SearchAccount',
                type: 'POST',
                data: '{_accountNumber:'+_accountNumber+'}',
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    UpdateTable(data);
                },
                error: function () {
                    alert('An error occurred while performing the search.');
                }
            });

            return false;
        }

Server code starts a query with this parameter and returns a list that is serialized in JSON for normal operation with jQuery. The server code is as follows:

        [HttpPost]
        public JsonResult SearchAccount(string _accountNumber)
        {
            MLIBEntities dbMLIB = new MLIBEntities();

            var searchResults = (from s in dbMLIB.Sets
                                 where s.setmap1 == _accountNumber
                                 select s);
            return Json(searchResults.ToList());
        }

As you can see, this is nothing complicated and works great when I start a project from VS2010 and use its virtual machine.

, Windows 2008 IIS 7. , PerformLookup, " ", , ajax .

- , IIS, VS2010? - IIS?

!

+5
2

URL- , , URL-:

url: '/SearchAjax/SearchAccount',

Url URL-:

url: '<%= Url.Action("SearchAccount", "SearchAjax") %>',

, :

function PerformLookup() {
    var _accountNumber = $('#accountNumber').val();
    $.ajax({
        url: '<%= Url.Action("SearchAccount", "SearchAjax") %>',
        type: 'POST',
        data: JSON.stringify({ _accountNumber: _accountNumber }),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            UpdateTable(data);
        },
        error: function () {
            alert('An error occurred while performing the search.');
        }
    });
    return false;
}

PerformLookup - , , HTML-:

<%= Html.ActionLink(
    "Perform search", 
    "SearchAccount", 
    "SearchAjax", 
    null, 
    new { id = "search" }
) %>

AJAXify:

$(function() {
    $('#search').click(function() {
        var _accountNumber = $('#accountNumber').val();
        $.ajax({
            url: this.href,
            type: 'POST',
            // Probably no need to send JSON request
            // so I've replaced it with a standard
            // application/x-www-form-urlencoded POST request
            data: { _accountNumber: _accountNumber },
            dataType: 'json',
            success: function (data) {
                UpdateTable(data);
            },
            error: function () {
                alert('An error occurred while performing the search.');
            }
        });
        return false;
    });
});

, , FireBug, , , AJAX .

+10

URL- javascript:

$.ajax({
    type: "POST",
    url: "/Appnamehere/Controller/Action", ...

..

0

All Articles