1

I have asked this question here: Kendo: bind remote datesource to form

I am unable to post a comment as I do not have a sufficient reputation, so I do apologise for the duplicate post.

How do I bind the results from a ajax request to a form?

    $.ajax({
    url: "Read?messageID=" + "123456",
    method: "get",
    type: "application/json",
    success: function (result) {
        var dataSource = new kendo.data.DataSource({
            data: result
        });
        console.log(result);
    },
    error: function (result) {
        console.log(result);
    }

});

I can see the data in the read but I do not know how to extract it and then bind it to a form. I have struggled to find documentation too.

This is the code I am using for my form input:

@Html.Label("message", "Note:", new { @class = "form-label" })
<input id="messages" class="form-control k-textbox" data-bind="value:message" />

I feel there is a missing piece in order to connect this together. I will keep searching and reading in the hopes of finding a solution but any help would be greatly appreciated.

Many thanks.

Jaffa
  • 23
  • 1
  • 1
  • 6
  • A couple of questions that may help here: 1) Are you able to provide a sample of the returned data that you are looking to bind? 2) Are you looking to bind multiple comments to multiple input controls or is it always binding 1 comment to 1 input field only? – David Shorthose Sep 16 '19 at 16:00

1 Answers1

0

Per https://docs.telerik.com/kendo-ui/framework/mvvm/overview :

  1. Bind the View to the View-Model. This is done by calling the kendo.bind method:

    kendo.bind($("#view"), viewModel);

Your viewModel must be an observable, and your equivalent of $("#view") must be a container that contains your entire form.

GaloisGirl
  • 1,476
  • 1
  • 8
  • 14
  • thank you for the comment. I have done exactly that yet there is still no data in the form fields. I have used the viewModel from the link you included but this works only with local data, in order to display the name from the remote source, do I set that value as null? I am not sure if I can include code in this reply, so I will refrain from doing so as I don't want my comment to be deleted :-) – Jaffa Sep 16 '19 at 14:57
  • How and when do you bind? I think in your success function, something like `kendo.bind($("#view"), new Observable(result))` should work, assuming `result` has the form `{message: 'your message',...}` – GaloisGirl Sep 18 '19 at 09:29