Example using MVVM and Datasource to create new object

5 posts, 0 answers
  1. James
    James avatar
    2 posts
    Member since:
    Dec 2008

    Posted 02 Apr 2012 Link to this post

    I am having a few problems and so far are unable to find an example which integrates the basic MVVM regsistration example with a datasource which posts the registration details servier side using Create.
    Is anybody able to provide a working example?

    var viewModel = kendo.observable({
    		assessmentDateSource: new kendo.data.DataSource({
    			transport: {
    				create: {
    					url: crudServiceBaseUrl + "/Assessment/Create",
    					type: "POST"
    				parameterMap: function (options, operation) {
    					if (operation !== "read" && options.models) {
    						return {
    							models: kendo.stringify(options.models)
    					return options;
    			}, batch: true,
    			schema: {
    				model: {
    					id: "AssessmentId"
    		firstname: "",
                    lastname: "",
                    create: function () {
                      //Datasource is empty here do I some how have to push the viewmodel into the datasource?
    Thanks in advance

  2. Peter Bulloch
    Peter Bulloch avatar
    13 posts
    Member since:
    Mar 2010

    Posted 27 May 2012 Link to this post

    I am in exactly the same quandary as you are. I cannot get the viewModel to initially populate anything!
  3. Joshua
    Joshua avatar
    13 posts
    Member since:
    Apr 2012

    Posted 04 Jun 2012 Link to this post

    If I understand your problem correctly, you just need to make sure your datasource has data before you bind the viewModel. Generally, I try to manually ensure that my datasources are populated in a specific order before binding by using the following trick:

    viewModel.dataSource1.fetch(function () {
    viewModel.dataSource2.fetch(function () {
    endo.bind($("content"), viewModel); });
  4. Peter Bulloch
    Peter Bulloch avatar
    13 posts
    Member since:
    Mar 2010

    Posted 04 Jun 2012 Link to this post

    Joshua - that looks rediculously simple!  I didn't notice the fetch command in the specs so will try that as soon as I can.  If it works I will buy you a beer.  Thanks for the feedback. 
  5. Mark
    Mark avatar
    15 posts
    Member since:
    Aug 2015

    Posted 13 Oct 2015 in reply to Joshua Link to this post

    But what if you are "Creating" a new object and not Editing?  I have no need to fetch because I am creating new.  I see all types of examples for Editing, but pretty much NO examples for Create New that doesn't involve a Grid.  Am I missing something here?  I am using Kendo IU, MVVM and Web API.  I'm just trying to get the data POSTed to the Web API by calling .sync from the datasource, but it never hits my API method and I don't receive any errors...anybody got sample code out there???  Thanks
Back to Top