本文介绍了在下拉选择更改时更新gridmvc数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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)











@ Html.Grid(Model.PlacementActivity).Columns(columns =>

{

columns.Add(c => c。 SubActivityName).Titled(SubActivityName)。Filterable(true);

columns.Add(c => c.CompletedVolumes).Titled(Completed Volumes)。可过滤(真正);



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







在html下拉控件的dropdownchange事件中,我需要更新网格的数据源。任何想法?



Ajax调用:

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 :

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:

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;
    }
}





我的尝试:



我尝试在ajax调用的帖子上返回一个视图但是不起作用。



What I have tried:

I tried returning a view on post of ajax call but does not work.

推荐答案








控制器代码返回型号:




Controller code returning Model:

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;
    }
}





我的尝试:



我尝试在ajax调用的帖子上返回一个视图但不起作用。



What I have tried:

I tried returning a view on post of ajax call but does not work.


这篇关于在下拉选择更改时更新gridmvc数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 08:48