Search code examples
model-view-controllerkendo-ui

C# MVC application with Kendo grid - passing multiple parameters


I need to send 2 parameters from my Kendo grid datasource to my controller. This is what my current code looks like:

@(Html.Kendo().Grid<OwnerViewModel>()
    .Name("OwnerGrid")
    .AutoBind(true)
    .Columns(columns =>
    {
        columns.Bound(pl => pl.RecordDate).Width(20).Title("Record Date").Format("{0:MM/dd/yyyy}");
        columns.Bound(pl => pl.Unit).Width(15).Title("Unit");
        columns.Bound(pl => pl.Own_Name).Width(45).Title("Name");
        columns.Bound(pl => pl.Own_Salutation).Width(45).Title("Salutation");
        columns.Bound(pl => pl.Own_MailAddr).Width(45).Title("Mailing Addr");
        columns.Bound(pl => pl.Own_City_St_Zip).Width(45).Title("City,State,Zip");
        columns.Bound(pl => pl.Own_PropAddr).Width(45).Title("Property Address");
    })
    .Pageable()
    .Sortable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(5)
        .Read(read => { read.Action("GetOwnerList", "Owners").Data("{ FileNum: " + @Model.FileNum + "}"); })
        )
    )

This will send a single parameter called 'FileNum' to GetOwnerList in the Owners controller. How would I set this up to send a second parameter along with FileNum?

Thank you.


Solution

  • What I have done in my applications for better readability is to use a JavaScript function name in the Data call like so:

        .DataSource(dataSource => dataSource
          .Ajax()
          .PageSize(5)
          .Read(read => read.Action("GetOwnerList", "Owners").Data("ReadOwnerListData")})
        )
    

    then, in your JavaScript:

        function ReadOwnerListData() {
            return {
                FileNum: Json.Serialize(Model.FileNum),
                SecondValue: [second value here]
            };
        }