KendoUI Grid Ajax Binding Parameters For Select

后端 未结 3 2067
梦如初夏
梦如初夏 2021-02-08 11:57

I have a basic KendoUI Grid for my ASP.NET MVC app which uses ajax binding for the read. I\'d like to enhance this so that a Form above the grid is used to help se

3条回答
  •  再見小時候
    2021-02-08 12:32

    Refer Pass Additional Data to the Action Method

    To pass additional parameters to the action use the Data method. Provide the name of a JavaScript function which will return a JavaScript object with the additional data:

    A working Search example listed below:

    Important: type="button" for the button; And AutoBind(false) for Grid; otherwise, it won’t work

    VIEW

    @model  IEnumerable
    @{
        ViewBag.Title = "Index";
    }
    
    
    
    
    

    Index

    @using (Html.BeginForm()) { @(Html.Kendo().Grid() .Name("ssgrid222") .Columns(columns => { columns.Bound(p => p.SampleDescription).Filterable(false).Width(100); columns.Bound(p => p.SampleCode).Filterable(false).Width(100); columns.Bound(p => p.SampleItems).Filterable(false).Width(100); }) .AutoBind(false) .Pageable() .Sortable() .Scrollable() .Filterable() .HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .Read(read => read.Action("Orders_Read", "Sample") .Data("getAdditionalData")) ) ) }

    Controller

    namespace KendoUIMvcSample.Controllers
    {
        public class SampleController : Controller
        {
            public ActionResult Index()
            {
                SampleModel AddSample = new SampleModel();
                Sample s1 = new Sample();
                return View(GetSamples());
            }
            public static IEnumerable GetSamples()
            {
                List sampleAdd = new List();
                Sample s12 = new Sample();
                s12.SampleCode = "123se";
                s12.SampleDescription = "GOOD";
                s12.SampleItems = "newone";
                Sample s2 = new Sample();
                s2.SampleCode = "234se";
                s2.SampleDescription = "Average";
                s2.SampleItems = "oldone";
                sampleAdd.Add(s12);
                sampleAdd.Add(s2);
                return sampleAdd;
            }
            public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request, CustomerSearchModel customerSearchModel)
            {
                string firstParam = customerSearchModel.FirstName;
                return Json(GetOrders().ToDataSourceResult(request));
            }
            private static IEnumerable GetOrders()
            {
                return GetSamples();
            }
        }
        public class CustomerSearchModel
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
        }
    }
    

    Model

    namespace KendoUIMvcSample.Models
    {
        public class SampleModel
        {
            public List samples;
        }
        public class Sample
        {
            public string SampleDescription { get; set; }
            public string SampleCode { get; set; }
            public string SampleItems { get; set; }
        }
    }
    

提交回复
热议问题