Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 MVCgrids

@model GBDashboard.Models.GBDashboardActivityDetailsForVerticalAndTeamModel
@Html.Grid(Model.PrePlacementActivity).Columns(columns =>
{
columns.Add(c => c.SubActivityName).Titled("SubActivityName").Filterable(true);
columns.Add(c => c.CompletedVolumes).Titled("Completed Volumes").Filterable(true);

}).WithPaging(8).Sortable(true)


And


@Html.Grid(Model.PlacementActivity).Columns(columns =>
{
columns.Add(c => c.SubActivityName).Titled("SubActivityName").Filterable(true);
columns.Add(c => c.CompletedVolumes).Titled("Completed Volumes").Filterable(true);

}).WithPaging(8).Sortable(true)



On dropdownchange event of html dropdown control, I need to update the datasource of the grid. Any ideas?

Ajax call :
JavaScript
function OnMonthsChange() {
    //alert('Test');
    var Month = $('#ddlMonths').val();

    $.ajax({
        type: "POST",
        url: "OnMonthChange", //'../../Controllers/ReportsController/SetSelectedHO',//'../../WebForms/ReportTest.aspx/GetRoomLocation', 
        contentType: "application/json; charset=utf-8",
        dataType: "html",
        data: '{Month: "' + Month + '" }',
        success: function (response) {
            alert('Success!!');
        },
        failure: function (response) {
            alert(response.d);
        }
    });

}



Controller code returning Model:
C#
public ActionResult OnMonthChange(string Month)
{
    try
    {
        // do calculations whatever you need to do
        // instantiate Model object
        Activities GBActivityDetailsForVerticalAndTeam = _service.GetActivityDetailsForVerticalAndTeam();
        return View(GBActivityDetailsForVerticalAndTeam);

    }
    catch (Exception)
    {

        throw;
    }
}


What I have tried:

I tried returning a view on post of ajax call but does not work.
Posted
Updated 8-Nov-16 14:58pm
v3
Comments
F-ES Sitecore 8-Nov-16 11:58am    
You need to return a view with the updated grids via an ajax post. If that "doesn't work" then post the code you have to see if someone can spot the issue.
Anjali0904 8-Nov-16 20:44pm    
When I try returning the view the success block of ajax call is not hit. I have updated my code.
F-ES Sitecore 9-Nov-16 4:02am    
Google "call mvc action jquery" to see examples of how to call an action, your "url" param is wrong for a start. Also have a look at this for tips on debugging ajax calls.

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