I've been following the steps outlined here to practice CRUD operations with the Kendo UI Grid:
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/batch-editing
And the incell editing is not actually saving the data changes I make. I've figured out that I'm running into ModelState errors, and so the ModelState.IsValid flag is false. Here is my edit method:
The exception that is raised is this:
"The key-value pairs that define an EntityKey cannot be null or empty"
Now the only part of my dataset that is null is the Name column, but this is set to Nullable in the edmx file, and the db field itself is set to nullable. So why do I keep getting this error message?
Another thing I'm confused about is how the demo (see the link above ) says to create a class called ProductViewModel in step 5. Why is this necessary when the Entity Framework has already created a Product table for you automatically? This seems to be an unneeded duplication of data. Thanks.
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/batch-editing
And the incell editing is not actually saving the data changes I make. I've figured out that I'm running into ModelState errors, and so the ModelState.IsValid flag is false. Here is my edit method:
public
ActionResult Editing_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix =
"models"
)]IEnumerable<TestTable> tests)
{
var results =
new
List<TestTable>();
foreach
(var modelStateValue
in
ViewData.ModelState.Values)
{
foreach
(var error
in
modelStateValue.Errors)
{
// Do something useful with these properties
var errorMessage = error.ErrorMessage;
var exception = error.Exception;
}
}
if
(tests !=
null
&& ModelState.IsValid)
{
using
(var delta =
new
DeltaHREntities())
{
foreach
(var test
in
tests)
{
var entity =
new
TestTable
{
ID = test.ID,
Name = test.Name,
DateCreated = test.DateCreated
};
results.Add(entity);
//store the test object for later use
delta.TestTables.Attach(entity);
//delta.Entry(test).State = EntityState.Modified;//why doesn't this work?
delta.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
}
delta.SaveChanges();
}
}
return
Json(results.ToDataSourceResult(request, ModelState, test =>
new
TestTable
{
Name = test.Name,
DateCreated = test.DateCreated,
ID = test.ID
}));
}
"The key-value pairs that define an EntityKey cannot be null or empty"
Now the only part of my dataset that is null is the Name column, but this is set to Nullable in the edmx file, and the db field itself is set to nullable. So why do I keep getting this error message?
Another thing I'm confused about is how the demo (see the link above ) says to create a class called ProductViewModel in step 5. Why is this necessary when the Entity Framework has already created a Product table for you automatically? This seems to be an unneeded duplication of data. Thanks.