简体   繁体   English

当JS变量的值为0(零)时,控制器API会将其替换为空字段(2sxc-DNN)

[英]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.

相关问题 2sxc-在JavaScript文件中放置@ Content.field变量 - 2sxc - Place a @Content.field var in a javascript file 2sxc-@foreach循环上的剃刀和JS之间的计算的var - 2sxc - Calculated vars between razor and JS on a @foreach loop 如何在 2sxc 模块中保存/加载自定义输入的值? - How do I save/load value for custom input in 2sxc module? 我如何等待创建/编辑实体模态 window 完成渲染并在 2sxc 模块中执行我的自定义 js 代码? - How can I wait for the create/edit entity modal window to finish rendering and execute my custom js code in 2sxc module? DNN-启用ClientResourceManagement时dnn.js参考重复 - DNN - dnn.js reference duplicated when ClientResourceManagement is enabled JavaScript-如何在点击事件回调函数中将输入值更新为“”时清空输入字段 - JavaScript - How to empty the input field when it value has been updated to “ ” in a click event callback function 无法在2sxc Mobius Forms应用程序中访问cshtml模板 - Cannot access the cshtml template in a 2sxc Mobius Forms app 2sxc | 将第二个按实体过滤的下拉列表添加到模板应用 - 2sxc | Add second filter by entity dropdown to template app 2sxc | 通过使用Javascript方法修剪来删除文件路径 - 2sxc | removing file path by trimming w/ Javascript method Angular JS字段仅使其值大于tan零有效 - Angular JS field valid only its value greater tan zero
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM