calculating fields editor .net libraries
calculating fields editor .net libraries
Hi,
I am new to datatables editor. I am trying to write a server side function that takes input values, and calculates another value, writes it to the db, and returns the value in the json.
I have tried to do something like:
var response =
new Editor(db, "Item", "ItemID")
.Model<ItemGenModel1>()
.
.
.
.
response.PostEdit += (sender, e) =>
{
//get a value
decimal w = e.Editor.Field("width").GetValue();
//set a value
e.Editor.Field("cubed").SetValue(w*w*w);
};
The GetValue returns a null dynamic object. I obviously am missing something. I was not able to find any examples that helped.
Any guidance would be appreciated.
Thanks,
Scott
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Hi Scott,
What you have looks very close, but you need to use
PreEdit
rather thanPostEdit
. ThePostEdit
code is run after the values have been written to the database.The other issue is that
Field().GetValue()
is not the method to use to get the POSTed value (that method is used for data that should be populated to the client-side (i.e. DataTables' get request).Use
e.Values["width"]
instead. You'll probably need to cast it to be an decimal as well, since it is stored as an object ((decimal)e.Values["width"]
should do it).Allan
Hi Allan,
Thanks. That pointed me in the right direction. In my initial question, I didn't go into a lot of detail. The actual data structure uses a number of left joins, so
e.Values["Item"]
was the actual call. From there, I used a generic dictionary object to get at the value. I ended up writing a functiongetvalues()
to query the values directly from the database that I need for the actual calculations. I am not sure if this is the most efficient, but it works. If there is a better way, I am all eyes. Thanks again.