How to just get dataSource?

1 Answer 39 Views
Application View
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Daochuen asked on 06 Aug 2021, 06:08 AM

Hello, 

I try to get dataSource from my MVC project but got syntax error. Could someone tell me what's wrong? Thanks.

Action method on MyController:

        public JsonResult Position_Read()
        {
                var entity = new PositionViewModel
                {
                   POS_ID = "10000",
                   POS_TYPE="INTER",
                   CREATE_DT = DateTime.Now
                };

                return Json(entity);
          }

 

JavaScript in View:

 <script>

        function GetServerSourceData() {
            var ds = new kendo.data.DataSource({
                type: "odata",
                transport: {
                    read: "/MySite/MyController/Position_Read"
                },
                schema: {
                    model: {
                        fields: {
                            POS_ID: { type: "string" }, 
                            POS_TYPE: { type: "string" }
    CREATE_DT: { type: "date" },
                        }
                    }
                }
            });
            return ds;
        } 

 </script>

                         

1 Answer, 1 is accepted

Sort by
0
Accepted
Anton Mironov
Telerik team
answered on 10 Aug 2021, 11:38 AM

Hi Daochuen,

Thank you for the code snippets and details provided.

In order to achieve the desired behavior, I would recommend using our DataSourceResult method that takes the request as a parameter.

The following demo represents the implementation and the behavior needed for the case(open ViewSource and observe the implementation in the Shared_DataSourceController.cs tab):

Give a try to the approach above and let me know if further assistance is needed.

Kind Regards,
Anton Mironov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Application View
Asked by
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Anton Mironov
Telerik team
Share this question
or