tags:

views:

101

answers:

2

I've had a look at the other questions on json and either they don't fully answer my question or I'm just not getting it.

What I want to do, from my mvc app, is to call an action in the controller on the keyup event of a textbox.

I want to then pass back the contents of the textbox, do some stuff with the data and then pass back a list of items which can then be added to a dropdown.

I'm completely new to json but [really] want to get stuck into it.

A: 

You can find a good example of using JsonResult in the Nerd Dinner project.

Nerd Dinner source code

CD
Thanks CD. I should know to use it as reference material.
griegs
+1  A: 

Something like this?:

$('input#textbox').keyup(function() {
    var textbox = $(this);

    $.ajax({ type: "POST", datatype = "json", data: textbox.serialize(),
        url: "<%= Url.Action("Action") %>",
        success : function(data) {
            textbox.val(data.TextBox);
        }
    })
});

public ActionResult Action(string TextBox)
{
    return Json(new { TextBox = TextBox.ToUpper() });
}
eu-ge-ne
+1 for the code. Thanks eu-ge-ne for the help but found the answer within NerdDinenr.
griegs