Get data from a MVC JsonResult action method

With jQuery it's now very easy to execute a post to a Asp.Net MVC action method and receive a answer in Json

Example for sending a parameter to the jsonresult method ( domein ) and receiving a jsonresult with available domain-names

    function FillAvailableDomeinenList(domein) {
        try{
            $.getJSON("/Domein/GetAvailableDomeinNames?domain=" + domein, null, function (data) {
                ClearSelect();
                FillSelect(data);
                $("#AvailableDomeinNames").show();
                ShowMessage("leeg", false);
            });
        }
        catch (ex) {
            alert(ex.message);
        }
    }

After that you can work with the data, in this case: fill a select list with options

    function FillSelect (data) {
        return $("#AvailableDomeinList").each(function() {
            if (this.tagName == 'SELECT') {
                var dropdownList = this;
                $.each(data, function(index, optionData) {
                    var option = new Option(optionData.Text, optionData.Value);
                                      
                    if ($.browser.msie) {
                        dropdownList.add(option);
                    }
                    else {
                        dropdownList.add(option, null);
                    }
                });
            }
        });
    }

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!