This is a migrated thread and some comments may be shown as answers.

Binding Grid to WebApi Result where the method needs a parameter

1 Answer 243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
osman
Top achievements
Rank 1
osman asked on 19 Sep 2016, 01:43 PM

Hi

 

Let me paint the picture. I am trying to build an application for the medical domain. Basically creating accounts which are responsible for paying the account. Then dependants linked to an account. And each account has transactions linked to it. That is the basic domain. I am trying to display a grid showing the account information. My architecture is as follows. Using entity framework 6 as my ORM. I have built some DTO's inside a model project that hold all my models which I intend to carry over the wire. I have a seperate asp mvc api project which will act as my data hub for different types of front ends, browser or mobile. At the moment I'm trying to build a front end using MVC 5 using the telerik kendo ui controls to make the ui nice. I'm struggling even after reading various articles on trying to achieve this. I have a method in my web api project which returns a list of accounts which I pasted below. After reading some new articles I've realised that it be better to refactor this method to return the kendo DataSourceResult and accept the modelbinder as a parameter. My question is. How do I pass the practiceid parameter into this method so that it only returns me a list of accounts that belong to the practice the user has logged into. I have also pasted my grid definition below.

[Route("api/Accounts")]public HttpResponseMessage GetAccountsByPractice(int practiceId){     IAccountRepository accountRepository = new AccountRepository("");     try     {         var results = accountRepository.GetAccountsByPractice(new Practice { PracticeId = practiceId });         return Request.CreateResponse(HttpStatusCode.OK, results);     }     catch (Exception)     {         throw;     }}

 

@(Html.Kendo().Grid<Medistat.MedistatWeb.Domain.Model.AccountDTO>()       .Name("accountGrid")       .Columns(columns =>       {           columns.Bound(p => p.AccountNumber);           columns.Bound(p => p.AccountHolderName).Width(100);           columns.Bound(p => p.IdNumber).Width(100);           columns.Bound(p => p.MedicalAidName).Width(100);           columns.Bound(p => p.MedicalAidNumber).Width(100);       })       .ToolBar(tools =>       {           tools.Create();       })       .Sortable()       .Pageable()       .Filterable()       .DataSource(dataSource =>           dataSource             .WebApi()             .Model(model =>             {                 model.Id(p => p.AccountId);             })             .Events(events => events.Error("error_handler"))             .Read(read => read.Url("http://localhost:54510/api/accounts"))             .Create(create => create.Url("http://localhost:54510/api/accounts"))       ))

 

1 Answer, 1 is accepted

Sort by
-1
Viktor Tachev
Telerik team
answered on 21 Sep 2016, 09:30 AM
Hello Osman,

Please examine the following resources that describe in detail how you can use Web API binding for the Grid component. They also illustrate how you can pass additional parameters to the methods.



Regards,
Viktor Tachev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
osman
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or