A newer version of this page is available. Switch to the current version.

ProcessCustomBinding - Available Binding Delegates

  • 3 minutes to read

To delegate the implementation of a grid view model population to Model-layer functions, call the view model's CardViewModel.ProcessCustomBinding method in a Controller. This method has several overloads with different sets of parameters. The result of the method call is that the intrinsic CardView view model object (CardViewModel) will be populated with the requested data. The view model object can then be passed to the CardView's Partial View as a Model and bound to the CardView with the extension's CardViewExtension.BindToCustomData method.

Method Overloads

From the following list of available overloads, you can select a specific overload depending on specific data processing features (such as sorting, filtering, paging) used within the CardView.

Overload List - C#

public void ProcessCustomBinding( CardViewCustomBindingGetDataCardCountHandler getDataCardCountMethod,
CardViewCustomBindingGetDataHandler getDataMethod );

public void ProcessCustomBinding( CardViewCustomBindingGetDataCardCountHandler getDataCardCountMethod,
CardViewCustomBindingGetDataHandler getDataMethod,
CardViewCustomBindingGetUniqueHeaderFilterValuesHandler getUniqueHeaderFilterValuesMethod );

public void ProcessCustomBinding( CardViewCustomBindingGetDataCardCountHandler getDataCardCountMethod,
CardViewCustomBindingGetDataHandler getDataMethod,
CardViewCustomBindingGetSummaryValuesHandler getSummaryValuesMethod );

public void ProcessCustomBinding( CardViewCustomBindingGetDataCardCountHandler getDataCardCountMethod,
CardViewCustomBindingGetDataHandler getDataMethod,
CardViewCustomBindingGetSummaryValuesHandler getSummaryValuesMethod,
CardViewCustomBindingGetUniqueHeaderFilterValuesHandler getUniqueHeaderFilterValuesMethod );

Method Parameters

The following list describes all available method parameters. Each parameter points to a typed method delegate.

Parameter Name Is Required? Delegated Method Type Description
getDataCardCountMethod Required CardViewCustomBindingGetDataCardCountHandler Always provide an implementation for the delegated method to return the total number of data cards.
getDataMethod Required CardViewCustomBindingGetDataHandler Always provide an implementation for the delegated method to return the data requested by the CardView.
getSummaryValuesMethod Optional CardViewCustomBindingGetSummaryValuesHandler If you use summaries within the CardView, provide an implementation for the delegated method to calculate and return values of the required summaries.
getUniqueHeaderFilterValuesMethod Optional CardViewCustomBindingGetUniqueHeaderFilterValuesHandler If you use filtering and display header filter buttons within the CardView, provide an implementation for the delegated method to return unique values to be displayed in the header filter popup list invoked for a CardView column.

Method Usage

The CardViewModel.ProcessCustomBinding method's simple usage scenario is given below - only required method delegates are specified.

Controller Code:


public partial class MyController: Controller {
        public ActionResult MyCardView() {
            return View("MyCardView");
        }
        //Standard CardView callback requests
        public ActionResult MyCardViewPartial() {
            var cardViewModel = CardViewExtension.GetViewModel("cardView"); //Obtain the CardView's state - the CardViewModel object
            ...
            cardViewModel .ProcessCustomBinding( //Call method with two required parameters
                MyBindingHandlers.MyGetDataCardCount, //Function to return the total number of data rows in a model
                MyBindingHandlers.MyGetData //Function to return data cards requested by the CardView
            );
            return PartialView("MyCardViewPartial", cardViewModel);
        }
        ...
    }

The following code sample shows a more versatile way to use the CardViewModel.ProcessCustomBinding method.

Controller Code:


public partial class MyController: Controller {
        public ActionResult MyCardView() {
            return View("MyCardView");
        }
        //Standard CardView callback requests
        public ActionResult MyCardViewPartial() {
            var viewModel = CardViewExtension.GetViewModel("cardView");
            if(viewModel == null)
                //Initialize the CardView state on the first load
                viewModel = CreateCardViewModel();
            return MyCustomBindingCore(viewModel);
        }
        //Paging operation requests
        public ActionResult MyPagingAction(CardViewPagerState pager) {
            var viewModel = CardViewExtension.GetViewModel("cardView");
            viewModel.ApplyPagingState(pager); //Update the CardView state with the processed paging state
            return MyCustomBindingCore(viewModel);
        }
        //Sorting operation requests
        public ActionResult MySortingAction(CardViewColumnState column, bool reset) {
            var viewModel = CardViewExtension.GetViewModel("cardView");
            viewModel.ApplySortingState(column, reset); //Update the CardView state with the processed sorting state
            return MyCustomBindingCore(viewModel);
        }

        PartialViewResult MyCustomBindingCore(CardViewModel viewModel) {
            ... //Some code to delegate model population to Model-layer functions (see the next item)
            return PartialView("MyCardViewPartial", viewModel);
        }

        static CardViewModel CreateCardViewModel() {
            var viewModel = new CardViewModel();
            viewModel.KeyFieldName = "ID";
            viewModel.Columns.Add("From");
            viewModel.Columns.Add("Subject");
            viewModel.Columns.Add("Sent");
            viewModel.Columns.Add("Size");
            viewModel.Columns.Add("HasAttachment");
            return viewModel;
        }
    }
See Also