views:

97

answers:

3

I have this jQuery get request:

$.get($(this).attr("href"), { "searchExpression": "schroders" }, function (result) {

    // do stuff

}, "html");

Which sends the get request to this Action Method:

public PartialViewResult Tabs(string searchExpression)
{
    return PartialView(new SearchViewModel
    {
        PagedFunds = _fundService.GetFunds(searchExpression)
    });
}

The $.get request sends a request to the Tabs method, but searchExpression is always an empty string. I've done this before and it's worked.. does anyone have any idea why either the data isn't being sent or the Model Binder isn't working?

edit: I've just discovered the version of jQuery being used is 1.2.6. Also, There's another JS framework being used on the site - Prototype, I think - so this is the complete function that I'm using for the GET, which manages the compatibility issues:

jQuery(document).ready(function ($) {
    $('.ActionControl a').click(function () {
        $.get($(this).attr("href"), { searchExpression: "schroders" }, function (result) {

            // do stuff

        }, "html");

        return false;
    });
});

does this offer any clues? Thanks

A: 

Did you debug it for the get parameter by firebug? See the params that you are sending through ajax.

If not solved than let me know.

gsoni
I've updated the message with a couple of points that might be having an impact on the success.
DaveDev
... btw - I checked with firebug, and I can see that `?searchExpression=schroders` is getting sent in the URL
DaveDev
A: 

Dave - could be that you need to explicitly decorate the action - i.e.:

[AcceptVerbs(HttpVerbs.Get)]

to ensure that it's not looking for a put/post request etc. I had wondered about the 'html' part previously, but that would only be related to the return type.

see comment above - but to put it in the answer:

dave - i did a test on this in a little test app with jquery 1.4.2 and it worked perfectly. it could be related to the version in use and/or the clash with prototype. you might have to alias the $.get function to jQuery.get (i think that's the syntax)

see http://docs.jquery.com/Using_jQuery_with_Other_Libraries

jim

jim
A: 

It turns out this is the the answer to the real issue is outlined here:

http://stackoverflow.com/questions/3362147/how-to-send-jquery-get-so-the-model-binder-can-bind-a-string-to-a-parameter

DaveDev