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

Pass scheduler appointment values to C# controller

1 Answer 223 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Gurdip
Top achievements
Rank 1
Gurdip asked on 29 Nov 2019, 12:28 AM

Hi,

I am using the scheduler but would like to pass the entered values in the scheduler (name, description, etc) to my C# controller, ideally within the kendo code in my view.

 

Could someone advise how to do this? I need to invoke a C# controller method on creation of an appointment.

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 03 Dec 2019, 04:17 PM

Hi Gurdip,

See the following demo and scroll down to the ASP.NET Core source section, which shows the Scheduler's configuration in the index.cshtml view and how the controller and the service that performs the CRUD operations with the data are implemented.

The Scheduler's DataSource is configured to call different actions when a specific operation is performed:

.DataSource(d => d
        .Events(e => e.Error("onError"))
        .Model(m =>
        {
            m.Id(f => f.TaskID);
            m.Field(f => f.Title).DefaultValue("No title");
            m.Field(f => f.OwnerID).DefaultValue(1);
            m.RecurrenceId(f => f.RecurrenceID);
        })
        .Read("Read", "Scheduler")
        .Create("Create", "Scheduler")
        .Destroy("Destroy", "Scheduler")
        .Update("Update", "Scheduler")
        .Filter(filters =>
        {
            filters.Add(model => model.OwnerID).IsEqualTo(1).Or().IsEqualTo(2);
        })
    )

When editing an existing event or creating a new one the respective actions ("Update" or "Create") in the controller are called and the event data is available through the action's TaskViewModel task parameters:

public virtual JsonResult Create([DataSourceRequest] DataSourceRequest request, TaskViewModel task)
        {
            if (ModelState.IsValid)
            {
                taskService.Insert(task, ModelState);
            }

            return Json(new[] { task }.ToDataSourceResult(request, ModelState));
        }

 

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Scheduler
Asked by
Gurdip
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or