查看没有在mvc中更新

时间:2017-11-14 07:25:24

标签: c# asp.net-mvc asp.net-mvc-4

我在使用MVC时遇到了问题。 在第一次运行应用程序时,我得到了20个结果。在过滤器中我得到4个结果。我能够在调试时看到模型中的那4个结果但是在查看它没有得到更新。我也尝试了ViewData和ViewBag,但结果是相同的。

任何人都可以帮助我吗?

以下是My IncentiveGroupConroller.cs

public ActionResult IncentiveGroupIndex(int? page)
                {
                    int pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
                    IPagedList<IncentiveGroup> PAGEDGROUP = null;
                    List<IncentiveGroup> IncentiveGroups = new List<IncentiveGroup>();
                    DataSet ds = new DataSet();
                    ds = SQLDatabaseOperations.ExecuteDataset(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(), CommandType.StoredProcedure, "GetIncentiveGroups");
                    DataTable dt = new DataTable();
                    dt = ds.Tables[0];
                    foreach (DataRow dr in dt.Rows)
                    {
                        IncentiveGroups.Add(new IncentiveGroup(dr));
                    }
                    ViewBag.IncentiveGroups = IncentiveGroups;
                    PAGEDGROUP = IncentiveGroups.ToPagedList(pageIndex, 10);
                   return View(PAGEDGROUP);
                }

         [HttpPost]
                public ActionResult Filter(IncentiveGroup oIncentiveGroup)
                {
                    IPagedList<IncentiveGroup> PagedIncenticeGroups = null;
                    List<IncentiveGroup> IncentiveGroups = new List<IncentiveGroup>();
                    DataSet ds = new DataSet();
                    ds = SQLDatabaseOperations.ExecuteDataset(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(), CommandType.StoredProcedure, "FilterIncentiveGroups", oIncentiveGroup.IncentiveGroupCode, oIncentiveGroup.IncentiveGroupName, oIncentiveGroup.IncentiveGroupShortName, oIncentiveGroup.IncentiveGroupStatus);
                    DataTable dt = new DataTable();
                    dt = ds.Tables[0];
                    foreach (DataRow dr in dt.Rows)
                    {
                        IncentiveGroups.Add(new IncentiveGroup(dr));
                    }
                    ViewBag.IncentiveGroups = IncentiveGroups;
                    PagedIncenticeGroups = IncentiveGroups.ToPagedList(1, IncentiveGroups.Count);
                    return View("IncentiveGroupIndex", PagedIncenticeGroups);
                   // return RedirectToAction("IncentiveGroupIndex", PagedIncenticeGroups);
                }

为控制器进行Follwling ajax调用

function filterIncentiveGroup() {
            var setIncentiveGroupStatus = $('input[name=IncentiveGroupStatus]:checked').val();
            var Test = {
                IncentiveGroupCode: $('#IncentiveGroupCode').val(),
                IncentiveGroupName: $('#IncentiveGroupName').val(),
                IncentiveGroupShortName: $('#IncentiveGroupShortName').val(),
                IncentiveGroupStatus: setIncentiveGroupStatus,
              };
            $.ajax({
                url: "/IncentiveGroup/Filter",
                data: JSON.stringify(Test),
                type: "POST",
                contentType: "application/json;charset=utf-8",
                dataType: "html",
                success: function (data) {
                    $('#myModal').modal('hide');
                    alert("Success");

                },
                error: function (errormessage) {
                    $('#myModal').modal('hide');
                    alert(errormessage.responseText);
                }
            });

        };

以下是我的IncentiveGroupIndex.cshtml

@using PagedList.Mvc
@model  PagedList.IPagedList<MPISMVC.Models.IncentiveGroup>

@{
    ViewBag.Title = "Incentive Group";
}
@*<h2>IncentiveGroupIndex</h2>*@
<div class="container-fluid" style="padding-top: 100px">
    <div class="panel panel-primary">
        <div class="panel-heading">Manage Incentive Group</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-4">

                    <button type="button" id="create" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>Add</button>
                    <button type="button" id="filter" class="btn btn-dafault"><span class="glyphicon glyphicon-filter"></span>Filter</button>
                </div>
                <div class="col-md-7">
                    <div class="pagination">
                        @*  Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
                        of @Model.PageCount *@  @Html.PagedListPager(Model, page => Url.Action("IncentiveGroupIndex", new { page }), new PagedListRenderOptions { DisplayEllipsesWhenNotShowingAllPageNumbers = true, MaximumPageNumbersToDisplay = 5, LinkToFirstPageFormat = "First", LinkToPreviousPageFormat = "Previous", LinkToNextPageFormat = "Next", LinkToLastPageFormat = "Last" })

                    </div>
                </div>
                <div class="col-md-1">
                    @*@Html.DropDownList("PageSize", new SelectList(new Dictionary<string, int> { { "10", 10 }, { "20", 20 },{ "50", 50 }, { "100", 100 } }, "Key", "Value", Model.PageSize), new { @class = "form-control" })*@
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>
                                    @Html.DisplayNameFor(model => model[0].IncentiveGroupCode)
                                </th>
                                <th>
                                    @Html.DisplayNameFor(model => model[0].IncentiveGroupName)
                                </th>
                                <th>
                                    @Html.DisplayNameFor(model => model[0].IncentiveGroupShortName)
                                </th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.IncentiveGroupCode)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.IncentiveGroupName)
                                    </td>

                                    <td>
                                        @Html.DisplayFor(modelItem => item.IncentiveGroupShortName)
                                    </td>
                                    <td>
                                        <button type="button" id="View" class="btn btn-sm btn-info" data-toggle="tooltip" title="View" onclick="details('@item.IncentiveGroupCode','View');"><span class="glyphicon glyphicon-eye-open"></span></button>
                                        <button type="button" id="Edit" class="btn btn-sm btn-primary" data-toggle="tooltip" title="Edit" onclick="details('@item.IncentiveGroupCode','Edit');"><span class="glyphicon glyphicon-pencil"></span></button>
                                        @*<button type="button" id="Delete" class="btn btn-sm btn-danger" data-toggle="tooltip" title="Delete" onclick="remove('@item.IncentiveGroupCode');"><span class="glyphicon glyphicon-trash"></span></button>*@
                                    </td>
                                </tr>

                            }
                        </tbody>
                    </table>
                </div>
            </div>
            @* <div class="row">
                <div class="pagination" style="margin-left: 400px">
                    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
                    of @Model.PageCount   @Html.PagedListPager(Model, page => Url.Action("IncentiveGroupIndex", new { page }))
                </div>
            </div>*@
        </div>
    </div>
</div>

image of filtered data count

0 个答案:

没有答案