Note that the other fields from the dataItem work fine. I get the TaxMethodPreference and AssetClassID without a problem. I also tried AssetNbr just to see if it worked and it does. It is only the date field that I can't seem to figure out how to pass.
This is the viewmodel:
public
class
AddTransactionViewModel
{
public
int
AddTransactionID {
get
;
set
; }
public
int
FarmID {
get
;
set
; }
public
int
Year {
get
;
set
; }
[Display(Name =
"Asset Nbr"
)]
[Required]
public
string
AssetNbr {
get
;
set
; }
[UIHint(
"AssetTransactionCodeEditor"
)]
[Required]
public
KMAR105.Data.Depr.AssetTransactionCode AssetTransactionCode {
get
;
set
; }
[UIHint(
"TaxClassBookMethodEditor"
)]
[Required]
public
KMAR105.Data.Depr.ClassBookMethod TaxClassBookMethod {
get
;
set
; }
[UIHint(
"BonusDepreciationRateEditor"
)]
[Required]
public
KMAR105.Data.Depr.DepreciationRate BonusDepreciationRate {
get
;
set
; }
[Display(Name =
"Description"
)]
[Required]
public
string
Description {
get
;
set
; }
[Display(Name =
"In Service Date"
)]
[DataType(DataType.Date)]
[Required]
public
DateTime InServiceDate {
get
;
set
; }
[Display(Name =
"Cost Basis"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
? OriginalCost {
get
;
set
; }
[Display(Name =
"Asset Type"
)]
[Required]
public
int
AssetTypeID {
get
;
set
; }
[Display(Name =
"Bus %"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:P2}"
)]
[Range(0.0, 1.0)]
public
double
BusinessPercent {
get
;
set
; }
[Display(Name =
"Qty"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
OriginalQuantity {
get
;
set
; }
[Display(Name =
"Sect 179"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
? ExpenseDeduction {
get
;
set
; }
[Display(Name =
"Bonus"
)]
public
double
TakeBonusDepr {
get
;
set
; }
[Display(Name =
"Related Asset Nbr"
)]
public
string
RelatedAssetNbr {
get
;
set
; }
[Display(Name =
"Comment"
)]
public
string
Comment {
get
;
set
; }
[Display(Name =
"Units Use"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:#,###,##0.00}"
)]
[Range(0.0, 9999999.99)]
public
double
? UnitsUse {
get
;
set
; }
[Display(Name =
"Previously Purchased"
)]
public
bool
PreviouslyPurchased {
get
;
set
; }
[Display(Name =
"Prior Depr"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
? PriorDepreciation {
get
;
set
; }
[Display(Name =
"Salvage"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
? SalvageValue {
get
;
set
; }
[Display(Name =
"Avg Conv"
)]
public
int
AveragingConventionID {
get
;
set
; }
[Display(Name =
"Depr Meth"
)]
public
int
DepreciationMethodID {
get
;
set
; }
[Display(Name =
"Life"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
RecoveryPeriod {
get
;
set
; }
[Display(Name =
"Mgmt Basis"
)]
[DisplayFormat(ApplyFormatInEditMode =
true
, DataFormatString =
"{0:###,###,##0.00}"
)]
[Range(0.0, 999999999.99)]
public
double
? MgmtBasis {
get
;
set
; }
[Display(Name =
"Mgmt Class Book Method"
)]
public
int
MgmtClassBookMethodID {
get
;
set
; }
[Display(Name =
"Orig Tax Class Book Method"
)]
public
int
OrigTaxClassBookMethodID {
get
;
set
; }
[Display(Name =
"Transfer Date"
)]
[DataType(DataType.Date)]
public
DateTime TransferDate {
get
;
set
; }
[Display(Name =
"1st Yr Conv"
)]
public
string
TaxAveragingConvention {
get
;
set
; }
[Display(Name =
"Tax Meth"
)]
public
string
TaxDepreciationMethod {
get
;
set
; }
[Display(Name =
"Last Person"
)]
public
string
LastPerson {
get
;
set
; }
[Display(Name =
"Tax Pref"
)]
public
string
TaxMethodPreference {
get
;
set
; }
}
This is the grid in the view:
@(Html.Kendo().Grid<KMAR105.MVC.Depr.Models.AddTransactionViewModel>()
.Name(
"addTranGrid"
)
.Columns(columns =>
{
columns.Command(command => command.Destroy().Text(
"Dlt"
)).Width(100);
columns.Bound(p => p.AssetNbr).Title(
"#"
).Width(70)
.ClientFooterTemplate(
"Cnt: #=count#"
);
columns.Bound(p => p.AssetTransactionCode).Title(
"ATIGD"
).Width(100).ClientTemplate(
"#: data.AssetTransactionCode != null ? AssetTransactionCode.Code : '' #"
);
columns.Bound(p => p.Description).Title(
"Description"
).Filterable(
false
).Width(210);
columns.ForeignKey(p => p.AssetTypeID, @Model.AssetTypes,
"DVID"
,
"DomainValue"
)
.Title(
"New?"
).Width(100);
columns.Bound(p => p.BusinessPercent).Title(
"Bus %"
).Filterable(
false
).Width(90);
columns.Bound(p => p.OriginalQuantity).Title(
"Qty"
).Filterable(
false
).Width(90)
.HtmlAttributes(
new
{ @
class
=
"text-right"
});
columns.Bound(p => p.InServiceDate).Title(
"Date"
).Width(100);
columns.Bound(p => p.OriginalCost).Title(
"Cost Basis"
).Filterable(
false
).Width(100)
.ClientFooterTemplate(
"Total: #= kendo.format('{0:C2}',sum)#"
)
.HtmlAttributes(
new
{ @
class
=
"text-right"
});
columns.Bound(p => p.ExpenseDeduction).Title(
"Sect 179"
).Filterable(
false
).Width(100)
.ClientFooterTemplate(
"Total: #= kendo.format('{0:C2}',sum)#"
)
.HtmlAttributes(
new
{ @
class
=
"text-right"
});
columns.Bound(p => p.BonusDepreciationRate).Title(
"Bonus"
).Width(140).ClientTemplate(
"#: data.BonusDepreciationRate != null ? BonusDepreciationRate.Rate : '0.00' #"
);
columns.Bound(p => p.TaxClassBookMethod).Title(
"Tax Method"
).Width(140).ClientTemplate(
"#: data.TaxClassBookMethod != null ? TaxClassBookMethod.Description : '' #"
);
columns.ForeignKey(p => p.DepreciationMethodID, @Model.DepreciationMethods,
"DVID"
,
"DomainValue"
)
.Title(
"Depr Meth"
).Filterable(
false
).Width(115);
columns.Bound(p => p.RecoveryPeriod).Title(
"Life"
).Filterable(
false
).Width(90);
columns.Bound(p => p.UnitsUse).Title(
"Units Use"
).Filterable(
false
).Width(85)
.HtmlAttributes(
new
{ @
class
=
"text-right"
});
columns.Bound(p => p.Comment).Title(
"Comments"
).Filterable(
false
).Width(150);
columns.Bound(p => p.RelatedAssetNbr).Title(
"Rel Ast #"
).Filterable(
false
).Width(80);
columns.Bound(p => p.AveragingConventionID).Title(
"1st Yr Conv"
).Hidden(
true
).Width(80);
columns.Bound(p => p.TaxMethodPreference).Title(
"TaxPref"
).Hidden(
true
).Width(80);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Navigatable()
.Sortable()
.Scrollable(scr => scr.Height(650))
.Filterable()
.Events(events => events.Edit(
"grid_OnEdit"
))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(
true
)
.ServerOperation(
false
)
.Events(events => events.Error(
"error_handler"
))
.Aggregates(aggregates =>
{
aggregates.Add(p => p.AssetNbr).Count();
aggregates.Add(p => p.OriginalCost).Sum();
aggregates.Add(p => p.ExpenseDeduction).Sum();
})
.Model(model =>
{
model.Id(p => p.AddTransactionID);
//model.Field(p => p.AssetNbr).DefaultValue(Model.MaxAssetNbr);
model.Field(p => p.FarmID).DefaultValue(Model.FarmID);
model.Field(p => p.Year).DefaultValue(Model.Year);
model.Field(p => p.AssetTypeID).DefaultValue(Model.DefaultAssetTypeID);
model.Field(p => p.InServiceDate).DefaultValue(Model.DefaultInServiceDate);
model.Field(p => p.OriginalCost).DefaultValue(0.0);
model.Field(p => p.ExpenseDeduction).DefaultValue(0.0);
model.Field(p => p.TakeBonusDepr).DefaultValue(0.0);
model.Field(p => p.UnitsUse).DefaultValue(0.0);
model.Field(p => p.PreviouslyPurchased).DefaultValue(
false
);
model.Field(p => p.BusinessPercent).DefaultValue(1.0);
model.Field(p => p.OriginalQuantity).DefaultValue(1.0);
model.Field(p => p.AssetTransactionCode).DefaultValue(
new
KMAR105.Data.Depr.AssetTransactionCode() { Code =
""
});
model.Field(p => p.TaxClassBookMethod).DefaultValue(
new
KMAR105.Data.Depr.ClassBookMethod() { Description =
""
});
model.Field(p => p.BonusDepreciationRate).DefaultValue(
new
KMAR105.Data.Depr.DepreciationRate() { Rate = 0.00 });
model.Field(p => p.PriorDepreciation).Editable(
false
).DefaultValue(0.0);
model.Field(p => p.SalvageValue).Editable(
false
).DefaultValue(0.0);
model.Field(p => p.AveragingConventionID).Editable(
false
).DefaultValue(0);
model.Field(p => p.DepreciationMethodID).Editable(
true
).DefaultValue(0);
model.Field(p => p.RecoveryPeriod).Editable(
true
).DefaultValue(0.0);
model.Field(p => p.TransferDate).Editable(
false
).DefaultValue(Model.DefaultTransferDate);
model.Field(p => p.TaxMethodPreference).Editable(
false
).DefaultValue(Model.TaxMethodPreference);
})
.Read(read => read.Action(
"New_Read_AddTransactions"
,
"AddTransaction"
,
new
{ year = Model.Year, farmID = Model.FarmID }))
.Create(
"New_Editing_Create"
,
"AddTransaction"
,
new
{ year = Model.Year, farmID = Model.FarmID })
.Update(
"New_Editing_Update"
,
"AddTransaction"
)
.Destroy(
"New_Editing_Destroy"
,
"AddTransaction"
)
)
)
This is the editor:
@using xxx.Models
@using System.Collections
<
script
>
function filterTaxClassBookMethods() {
//var row = $(event.srcElement).closest("tr");
//var grid = $(event.srcElement).closest("[data-role=grid]").data("kendoGrid");
var row = $("#TaxClassBookMethod").closest("tr");
var grid = $("#TaxClassBookMethod").closest("[data-role=grid]").data("kendoGrid");
var dataItem = grid.dataItem(row);
var inServiceDate = dataItem.InServiceDate;
return { taxMethodPreference: dataItem.TaxMethodPreference, depreciationBookID: 1002, assetClassID: dataItem.AssetTransactionCode.AssetClassID, inServiceDate: inServiceDate };
}
</
script
>
@(Html.Kendo().DropDownList()
.Name("TaxClassBookMethod") // Name of the widget should be the same as the name of the property
.DataValueField("ClassBookMethodID") // The value of the dropdown
.DataTextField("Description") // The text of the items
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("GetClassBookMethods", "AddTransaction").Data("filterTaxClassBookMethods")).ServerFiltering(true);
})
.Events(e => e.Change("taxclassbookmethod_changed").DataBound("function(){this.trigger('change')}"))
)