Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi.. I want to use AJAX with MVC. Any links or any sort of help would be highly appreciated.
Let's say I have a text-box where I have to enter some name. When I enter any character on it then it should bring all the names similar to the character I entered, from my database.
Posted

below is a simple example to use ajax in a mvc project


XML
function BindDropdown() {
        $.ajax({
            url: "/apiFolder/ApiName",
            type: "Get",
            dataType: 'json',
            success: function (datas, status, xhr) {
                var vItems = "<option value='0'> ..Select.. </option>";
                $("#ddlRDName").empty();
                $.each(datas, function (index, rd) {
                    vItems += "<option value='" + rd.RoD_ID + "'> " + rd.RoD_Name + " </option>";
                });
                $("#ddlRDName").html(vItems);
                $("#ddlRDName").val("0");
            },
            error: function (xhr, textStatus, errorThrown) {
                //$('#dialog-overlay').hide();
            }
        });
    }
 
Share this answer
 
v3
 
Share this answer
 
MVC is just the pattern in ASP.NET, rest is simply the web scripting and programming. You can definitely use ajax with ASP.NET MVC applications to load or submit data to the server asynchronously.

Here is a blog post of mine, A tip for ajax developers in ASP.NET MVC framework[^]. It covers all aspects of ajax requests in ASP.NET MVC.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900