Json ModelBinding no funciona desde Ajax en MVC3 RC2 [cerrado]

I'm trying to use Ajax with JSON model binding in MVC3 RC2 and for some reason the data is not getting through to the controller action method. There have been other posts on this topic, but some refer to older versions of MVC and none of those posts that I've found has hit the spot. Since I'm new to JSON, JSON ModelBinding and not that well experienced in jQuery Ajax calls, I could have easily missed something.

My starting point was Scott Guthrie's post http://bit.ly/btdFP5 introducing the MVC3 preview in the section Javascript and AJAX improvements, but I'm pulling map data off the Google API instead so my code is slightly different:

        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();

        var mb = { nelat: northEast.lat(), nelng: northEast.lng(), swlat: southWest.lat(), swlng: southWest.lng() };

                url: "/home/GetMarkers",
                type: "post",
                dataType: "json",
                contentTYpe: "application/json; charset=utf-8",
                success: function (result) {

La éxito function all works fine, so I've stopped the code listing there.

I have a class in the project's domain model for the lat/long co-ordinates:

Public Class MapBounds
    Public Property nelat As Double
    Public Property nelng As Double
    Public Property swlat As Double
    Public Property swlng As Double
End Class

and the Controller action is:

Function GetMarkers(ByVal mb As MapBounds) As JsonResult
    Dim objMarkers = ... get relevant data from database
    Return Json(objMarkers)
End Function

The posted JSON data observed via Firebug is (typically):


but the values returned the properties in the MapBounds object are all zero. I've tried various variations on passing parameters including passing individual values, but with no luck. The values are either zero or null.

Phil Haack's post - http://bit.ly/bUl21b - on sending JSON to an action method argument says that the JsonValueProviderFactory is now part of MVC3, but I checked anyway to see that it was present (and it is).

preguntado el 08 de enero de 11 a las 19:01

1 Respuestas

You have a typo in your contentType parameter which might prevent it from properly setting. It should be contentType y no contentTYpe.

Respondido el 09 de enero de 11 a las 11:01

Read doh moment there. Just goes to show that your brain sees what it expects to see. Thanks. - CrispinH

Hay una campaign to clean up Stack Overflow by removing these typo-related questions - we could really use your help! Would you mind pitching in a little by casting a close vote on this question? - Wesley Murch

Sorry, I do not consider those as off-topic questions and will not vote to close them. - Darin Dimitrov

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.