提交页面后如何刷新Kendo网格?

时间:2016-07-01 20:00:01

标签: asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc

我正在使用带有Telerik Kendo控件的asp MVC。我有一个带按钮和Kendo网格的页面。单击该按钮时,将调用该方法的HttpPost版本。此方法将值赋给名为sql的字符串变量并返回视图。当发生这种情况时,我希望网格能够刷新并访问该sql变量。最终,我将要使用该变量作为网格的来源,但我还不是那个部分;现在我只是想在提交后让网格刷新。我认为在提交表单时会触发网格的Read函数,但这种情况并没有发生。我在ReadLookup方法中有一个断点,单击提交按钮后它没有被点击。我怎样才能让它发挥作用?

所以这是我的观点:

enter image description here

这是名为Lookup_Lab.cshtml的视图中的(部分)代码:

<input id="btnSearch" type="submit" name="postFunction" value="apv no prt" />

@(Html.Kendo().Grid<DALubeBarcode.Models.ModelLookup>().Name("gridLookup")
                                .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Model(model => model.Id(m => m.analysisID))
                                    .Batch(true)
                                    .Read(read => read.Action("ReadLookup", "Home", new
                                    {
                                        sql = Model.query
                                    }))
                                 .PageSize(5)
                                )
                                .Columns(columns =>
                                {
                                    columns.Bound(m => m.customerID).Title("Customer ID");
                                    columns.Bound(m => m.unitNumber).Title("Unit Number");
                                    columns.Bound(m => m.origLocationID).Title("Location ID");
                                    columns.Bound(m => m.analysisID).Title("Analysis ID");
                                    columns.Bound(m => m.printed).Title("Printed");
                                    columns.Bound(m => m.dateReceived).Title("Date Received").Format("{0:MM/dd/yyyy}");
                                    columns.Bound(m => m.dateReport).Title("Date Received").Format("{0:MM/dd/yyyy}");
                                })
                            .Sortable()
                            .Selectable()
                .Pageable(x => x.PageSizes(new[] { 5, 10, 20, 50 }).Refresh(true))
                            .Resizable(resize => resize.Columns(true))
                    )

这是控制器代码:

public ActionResult Lookup_Lab(ModelLookup model)
        {
            ModelLookup newModel = new ModelLookup();
            if (model == null)
            {
                model = newModel;
            }

            string defaultSelection = "-- All -- ";

            model.ddCustomer = "0";
            List<ModelGenericDropdownString> customersListDropDown = new List<ModelGenericDropdownString>();
            List<ModelCustomer> customerList = new List<ModelCustomer>();
            customerList = data.GetCustomers();
            foreach (ModelCustomer customer in customerList)
            {
                ModelGenericDropdownString cust = new ModelGenericDropdownString
                {
                    value = customer.customerID,
                    text = customer.customerName + " - " + customer.customerID
                };

                if (customer.customerID != null && customer.customerID.Trim() != "")
                {
                    customersListDropDown.Add(cust);
                }
            }
            model.customers = customersListDropDown;


            model.ddOrigLocation = "0";
            List<TblLabFacility> labs = dataLab.GetLabFacilities();
            List<ModelGenericDropdownString> labList = new List<ModelGenericDropdownString>();
            foreach (TblLabFacility lab in labs)
            {
                labList.Add(
                    new ModelGenericDropdownString
                    {
                        text = lab.LabName.Trim(),
                        value = lab.LabCode.Trim()
                    }
                 );
            }
            model.locations = labList;

            return View(model);
        } // Lookup_Lab

        [HttpPost]
        public ActionResult Lookup_Lab(ModelLookup model, string postFunction)
        {
            if (postFunction == "apv no prt")
            {
                model.query = @"
                                SELECT
	                                  tblSampleInfo.Printed
	                                , tblSampleInfo.CustomerID
	                                , tblSampleInfo.UnitNumber
	                                , tblSampleInfo.OrigLocationID
	                                , tblSampleInfo.AnalysisID
	                                , tblSampleInfo.DateReceived
	                                , tblSampleInfo.DateReport
                                FROM 
	                                tblSampleInfo 
	                                INNER JOIN tblTestResults ON tblSampleInfo.AnalysisID = tblTestResults.AnalysisID
                                WHERE
	                                tblSampleInfo.Printed = 0
	                                AND 
	                                tblSampleInfo.DateReceived Between '2016-02-01' AND '2016-02-28'
	                                AND 
	                                tblSampleInfo.DateReport Is Null
	                                AND 
	                                tblTestResults.Approved = 1
	                                AND 
	                                tblSampleInfo.LabCode = '" + model.ddLocation + "'";                
            }

            // Fill location dropdown
            if (model.ddCustomer != "" && model.ddCustomer != null)
            {
                model.origLocations = data.GetLocationsByCustID(model.ddCustomer);
            }
            else
            {
                model.origLocations = new List<DataModelSample>();
            }

            // Fill customers dropdown
            List<ModelGenericDropdownString> customersListDropDown = new List<ModelGenericDropdownString>();
            List<ModelCustomer> customerList = new List<ModelCustomer>();
            customerList = data.GetCustomers();
            foreach (ModelCustomer customer in customerList)
            {
                ModelGenericDropdownString cust = new ModelGenericDropdownString
                {
                    value = customer.customerID,
                    text = customer.customerName + " - " + customer.customerID
                };

                if (customer.customerID != null && customer.customerID.Trim() != "")
                {
                    customersListDropDown.Add(cust);
                }
            }
            model.customers = customersListDropDown;

            // Fill lab location dropdown
            model.ddOrigLocation = "0";
            List<TblLabFacility> labs = dataLab.GetLabFacilities();
            List<ModelGenericDropdownString> labList = new List<ModelGenericDropdownString>();
            foreach (TblLabFacility lab in labs)
            {
                labList.Add(
                    new ModelGenericDropdownString
                    {
                        text = lab.LabName.Trim(),
                        value = lab.LabCode.Trim()
                    }
                 );
            }
            model.locations = labList;

            return View(model);
        } // Lookup_Lab - HttpPost

        public ActionResult ReadLookup([DataSourceRequest] DataSourceRequest request
            , string sql
            )
        {
            List<DataModelSample> samples = new List<DataModelSample>();

            return Json(samples.ToDataSourceResult(request));
        } // ReadLookup

我想要发生的是:

  1. 用户点击标有“apv no prt”
  2. 的按钮
  3. 表格已提交
  4. 方法Home / [HttpPost]调用Lookup_Lab()
  5. model.sql设置为
  6. Lookup_Lab将模型返回到视图
  7. Read_Lookup()被称为
  8. Read_Lookup()可以看到sql的值
  9. 相反,该过程在步骤5停止。如何让它继续并刷新网格?

0 个答案:

没有答案