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

How to ModelBind to ASP.net MVC and Datasource Model

1 Answer 186 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
axwack
Top achievements
Rank 1
axwack asked on 24 Aug 2012, 04:48 PM
I am trying to use MVC's model binding functionality. I have  a source that I need to submit to the server and then have it return a value called a Yield to Maturity. The issue is my form is bound to a viewModel. When I do a yieldSource.sync() , the form is submitted with my schema model but nothing is populated. 

Here is my code: Originally I was doing gets in the addYieldValues method but that didn't seem to do anything unless I put the values in an array.

Please help.

$(document).ready(function () {
        
           var viewModel = kendo.observable({
            
           order : {
                   allocations: [],
                   yieldCalcs: [],  
                   TradeDate: "",
                   SettleDate: "",
                   EventType:"",
                   TrustCode: "",
                   Broker: "",  
                   BondProceeds: function(){                                       
                               return this.get("UnderlyingPar") * (this.get("UnderlyingPrice")/100) + this.get("UpfrontFees");
                                       },
                   UnderlyingPar: "",
                   TrustFee: "",
                   RemarkFee: ".",
                   WrapFee: "",
                   LiquidFee: "",
                   BMASIFMA: "",
                   UnderlyingPrice: "",
                   UpfrontFees: "",
                   FloaterAmount:"",
                   InverseFloatPar:"",
                   LeverageRatio: function(){
                       return this.get("FloaterAmount")/this.get("InverseFloatPar");
                   },
                   ResidualYield: function(){
                    
                   },
                   ResidualAmount: "",
                   ResidualPrice: function(){
                       return this.TotalAmount()/this.get("InverseFloatPar")*100;
                   },
                   InterestOnFloat: function(){    
                       return this.get("FloaterAmount")*this.get("BMASIFMA");
                   },
                   InterestOnAssets: function(){
                       return this.get("UnderlyingPar") * this.get("UnderlyingCoupon");
                   },
                   ProgramFees: function(){
                       return (this.get("UnderlyingPar") * (this.get("TrustFee") + this.get("WrapFee"))) + (this.get("FloaterAmount") * (this.get("RemarkFee") +
                       this.get("LiquidFee")));
                   },
                   UnderlyingYield: ".0375",
                   UnderlyingCoupon: ".05",
                   TerminationDate:"",
                   EffectiveCoupon: function(){
                       return  (this.InterestOnAssets() - this.InterestOnFloat() - this.ProgramFees())/this.get("InverseFloatPar");
                   },
 
                   TotalAmount: function(){
                                      return this.get("UnderlyingPar") * (this.get("UnderlyingPrice")/100) - this.get("FloaterAmount");
                                       },
                   ResAccInt: function(){
                   }
            },
            yieldSource: new kendo.data.DataSource({
                      pageSize: 1,
                      data: this.order,                
                      transport: {
                                  read: {                                       
                                      url: "@Url.Action("GetYield","Home")",
                                      dataType: "json"
                                   },
                                  create : {
                                  url: "@Url.Action("GetYield","Home")",
                                      dataType: "json"
                                  }
                      },
                      schema: {                        
                           model: {
                               fields: {
                                   SettleDate:  { Type: "Date", validation: {required: true }},
                                   TerminationDate:  {Type: "Date",  validation: {required: true }},
                                   EffectiveCoupon: { Type: "Number", validation: {required: true }},
                                   ResidualPrice:  { Type: "Number",validation: {required: true }},
                                   EffectiveCoupon: {Type: "Number",validation: {required: true}},
                                   ResidualYield: {Type: "Number",validation: {required: true}},
                                   ResidualPrice: {Type: "Number",validation: {required: true}},
                                   InverseFloatPar: {Type: "Number",validation: {required: true}},
                                   LeverageRatio: {Type: "Number",validation: {required: true}},
                                   UnderlyingPar: {Type: "Number",validation: {required: true}},
                                   UnderlyingPrice: {Type: "Number",validation: {required: true}},
                                   UnderlyingYield: {Type: "Number",validation: {required: true}},
                                   UnderlyingCoupon: {Type: "Number",validation: {required: true}},
                                   EventType: {Type: "Number",validation : {required: true}},
                                   TrustCode: {Type: "Number",validation : {required: true}},
                                   Broker: {Type: "Number",validation : {required: true}},
                                   BondProceeds: {Type: "Number",validation : {required: true}},
                                   BMASIFMA: {Type: "Number",validation : {required: true}},
                                   WrapFee: {Type: "Number",validation : {required: true}},
                                   RemarkFee: {validation : {required: true}},
                                   LiquidFee: {validation : {required: true}},
                                   ResccInt: {validation : {required: true}},
                                   TotalAmount: "TotalAmount"
                                   }
                               }
                           },
                       parameterMap: function(options, operation){
                           if(operation=="create"){
                               console.log(options);
                                 
                                   return { models: kendo.stringify(options.models)};
                           }  
                           return options;                        
                       }
                        
            }),
            addYieldValues: function(){
                 
                    
                   this.yieldSource.add(this.viewModel);
                   this.yieldSource.sync();
                    
               },

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 Aug 2012, 04:06 PM
Hi,

The MVC model binder will not be able to parse the data in the used format. I can suggest to check this code library which demonstrates how to format the parameters in the parameterMap function.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
axwack
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or