I have a fairly simple Kendo Grid in a Razor page that posts to its Model via Ajax
All the parameter on the grid are set correctly (Forgery Token, etc). Also set the right camel case in startup.cs:
.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
The post successfully hits the OnPostUpdate function but the class only has empty members:
If I access the Form via the Request object (not the "request" object), I can see all members correctly posted but the "doesnotwork" instance only contains empty fields as if the deserialization did not work correctly.
public JsonResult OnPostUpdate([DataSourceRequest] DataSourceRequest request, hrFeedback doesnotwork)
{
hrFeedback tFeedback=null;
try
{
var t=CU.CGuid(Request.Form["FeedID"]);
tFeedback = _context.tblFeedback.Where(s => s.FeedID == t).FirstOrDefault();
if (tFeedback != null)
{
tFeedback.Feedback = Request.Form["Feedback"];// feedback.Feedback;
tFeedback.FollowedUp = Request.Form["FollowedUp"]; // feedback.FollowedUp;
tFeedback.Subject = Request.Form["Subject"]; // feedback.Subject;
tFeedback.Unsubscribe = CU.CDate(Request.Form["Unsubscribe"]).DateTime; // feedback.Unsubscribe;
_context.tblFeedback.Update(tFeedback);
_context.SaveChanges();
}
else
return new JsonResult(Content("Feedback ID not found")); //Is there a better way to tell the grid that the update failed?
}
catch (Exception e)
{
}
return new JsonResult(new[] { tFeedback }.ToDataSourceResult(request, ModelState));
}
I also assume that my OnPostRead does not work right as I can see the filter/sort coming in via Request.Form["filter"] but the ToDataSourceResult seems not to take these values as the result on the page never shows filter or search results (always all rows are displayed)
public JsonResult OnPostRead([DataSourceRequest] DataSourceRequest request)
{
var t = new JsonResult(_context.tblFeedback.ToDataSourceResult(request));
return t;
}
Can anybody tell me what I am forgetting?
I have another page that works just fine using the OnPostUpdate and its class value but I cannot see any difference between the two
Thanks