João Gomes João Gomes - 3 years ago 155
C# Question

When a JS var has the value 0 (zero), controller API replaces it with empty field (2sxc - DNN)

I use 2sxc (DNN) to pass some form data into an entity trough this js:

$2sxc(@Dnn.Module.ModuleID).webApi.post("Controller/Create", {}, {
qtitle: "@Content.title",
date: $todaydate,
user: "@Dnn.User.Username",
q1sel: $q1res,
q1val: $q1val
}


And this controller:

[HttpPost]
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.Admin)]
[ValidateAntiForgeryToken]
public bool Create(dynamic postController)
{
var quizvals = new Dictionary<string, object>();

quizvals.Add("qtitle", postController.qtitle.ToString());
quizvals.Add("date", postController.date.ToString());
quizvals.Add("user", postController.user.ToString());
quizvals.Add("q1sel", postController.q1sel.ToString());

App.Data.Create("Quiz10q5o_entries", quizvals, "Anonymous");

return true;
}


I tried quite a few data types and they all work fine, with or without ToString, but when any of the $vars has a 0 (zero, JS numeric), the field is passed has empty into the entity row.

Can anyone help me understand why this happens? Is some type of conversion needed here?

Best regards,
João Gomes

Answer Source

I reviewed your work and it doesn't look like anything is wrong. It also seems to write 0 into the number field, as it should:

enter image description here

to me it looks like just the list-view in admin hides these values:

enter image description here

Could it be that this is all?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download