views:

19

answers:

1

I have controller method in my MVC application that I am calling using the jQury $.post.... The call is executing correctly, processing and sending a valid result back to the view for rendering. If I alert the result everything is received on teh client as expected but the data is not rendered to the view.

The controller mehtod is as below

public ActionResult SearchWithCriteria(string search)
{
    var companyList = new Companies().SearchCompanies(search);
    return  PartialView ("Partials\\SearchResults", new SearchViewModel() { SearchResults = companyList });
}

and the jQuery is as below

$("#submit").bind("click", function () {
                var searchCriteria = $("#SearchCriteria").val();
                if (searchCriteria.length > 0) {
                    $.post('/Search/SearchWithCriteria', { search: searchCriteria }, function (data) {
                        alert(data);
                        $("companyDetailsSearch").html(data);
                    });
                }
            });

The partial is strongly typed and if I put breakpoints on the code I can step through it, but as I say nothing is rendered by the view.

+3  A: 

Should...

$("companyDetailsSearch").html(data);

...really be...

$("#companyDetailsSearch").html(data); // use '#' for id's, '.' for classes


edit: Somehow I managed to write that in the most obfuscated way ever. Basically, 'companyDetailsSearch' isn't a valid selector. If that's the ID of an element, use the '#' symbol first...

jmar777
Thanks for that, it's working now. Had to be something simple!
simon_bellis