[英]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)通过此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. 我尝试了很多数据类型,无论是否使用ToString,它们都可以正常工作,但是当$ vars中的任何一个为0(零,JS数字)时,传递给该字段的字段为空。
Can anyone help me understand why this happens? 谁能帮助我了解为什么会这样? Is some type of conversion needed here? 这里需要某种类型的转换吗?
Best regards, João Gomes 最好的问候,JoãoGomes
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: 它似乎也将0写入数字字段,因为它应该:
to me it looks like just the list-view in admin hides these values: 对我来说,似乎只是admin中的列表视图隐藏了这些值:
Could it be that this is all? 难道这就是全部吗?
My guess is that you are writing to a number-field, and using a string. 我的猜测是您正在写一个数字字段,并使用一个字符串。 Try casting it to a Int32 or similar and I believe you should be good to go. 尝试将其转换为Int32或类似的格式,我相信您应该会很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.