Good afternoon. My Kendo Grid allows me to create new records, but when I try to update a record I get the following error:
"No parameterless constructor defined for this object"
I should note that if I do not change anything when the update popup appears and just click the update button, it works fine. Only if I change something and then click update do I get the error.
Here is my grid code:
Here is the controller code:
Does anyone know what's going on here?
"No parameterless constructor defined for this object"
I should note that if I do not change anything when the update popup appears and just click the update button, it works fine. Only if I change something and then click update do I get the error.
Here is my grid code:
@(Html.Kendo().Grid<ExpenseReport.MVC.Models.ExpenseReportModel>()
.Name(
"Grid"
)
.Columns(columns =>
{
columns.Bound(p => p.ExpenseReportId).Visible(
true
);
columns.Bound(p => p.ExpenseLineItemId).Visible(
true
);
columns.Bound(p => p.ExpenseTypeDesc).Title(
"Expense Type"
);
columns.Bound(p => p.City).Title(
"City"
);
columns.Bound(p => p.StateName).Title(
"State"
);
columns.Bound(p => p.Date).Format(
"{0:d}"
).Title(
"Date"
);
columns.Bound(p => p.Amount).Title(
"Amount"
);
columns.Bound(p => p.EndingMileage).Title(
"Ending Mileage"
);
columns.Bound(p => p.BeginningMileage).Title(
"Beginning Mileage"
);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create().HtmlAttributes(
new
{ id =
"btnAdd"
}))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName(
"NewExpense"
).Window(w => w.Width(500)))
.Pageable()
.Scrollable()
.HtmlAttributes(
new
{ style =
"height:430px; width=100%"
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error(
"error_handler"
))
.Model(model =>
{
model.Id(p => p.ExpenseReportId);
model.Id(p => p.ExpenseLineItemId);
})
.Create(create => create
.Action(
"EditingPopup_Create"
,
"ExpenseReport"
)
.Data(
"erLineItemsCreateData"
))
//.Read(read => read
// .Action("EditingPopup_Read", "ExpenseReport")
// .Data("erLineItemsReadData"))
.Update(update => update
.Action(
"EditingPopup_Update"
,
"ExpenseReport"
).Type(HttpVerbs.Post)
.Data(
"erLineItemsUpdateData"
))
.Destroy(update => update
.Action(
"EditingPopup_Destroy"
,
"ExpenseReport"
).Type(HttpVerbs.Post)))
)
<script>
function
error_handler(e) {
if
(e.errors) {
var
message =
"Errors:\n"
;
$.each(e.errors,
function
(key, value) {
if
(
'errors'
in
value) {
$.each(value.errors,
function
() {
message +=
this
+
"\n"
;
});
}
});
alert(message);
}
}
//pass additional data to the READ action method
function
erLineItemsReadData() {
return
{
expenseReportId:
"@ViewBag.ExpenseReportId"
};
}
function
erLineItemsCreateData() {
return
{
expenseReportId:
"@ViewBag.ExpenseReportId"
};
}
function
erLineItemsUpdateData() {
return
{
expenseReportId:
"@ViewBag.ExpenseReportId"
,
expenseLineItemId:
"@ViewBag.ExpenseLineItemId"
};
}
Here is the controller code:
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult EditingPopup_Update([DataSourceRequest] DataSourceRequest request, ExpenseReportModel erLineItem,
int
expenseReportId,
int
expenseLineItemId)
{
if
(erLineItem !=
null
&& ModelState.IsValid)
{
globalKip.UpdateExpenseReportLineItem(expenseReportId, erLineItem.ExpenseTypeDesc, erLineItem.Date, erLineItem.Amount, erLineItem.City, erLineItem.StateName, erLineItem.EndingMileage, erLineItem.BeginningMileage);
}
return
Json(
new
[] { erLineItem }.ToDataSourceResult(request, ModelState));
}
Does anyone know what's going on here?