【问题标题】:how to display datetime arraylist in textboxfor in table Partial view mvc如何在表格部分视图mvc中的textboxfor中显示日期时间数组列表
【发布时间】:2020-02-17 17:17:03
【问题描述】:

我有 arraylist 包含 id、datetime 和 boolen(Chechbox) 当它仅在表中绑定时,如果它在 textboxfor 中绑定(我需要使日期可编辑)它在标签中绑定正确,则日期时间不会以写入方式绑定。

    <tbody id="employeeScheduleList">
    @if (Model != null && Model.R != null && Model.R.Count() > 0)
        {
            foreach (var file in Model.R)
            {
            <tr>
                <td>
                    <div class="form-group">
                        @if (@file.ReceivingDateValue != null)
                        {
                            @file.ReceivingDateValue.Value.ToShortDateString()
                        }
                         @Html.TextBoxFor(m => file.ReceivingDateValue, new { @class = "form-control ReceivingDate ", type = "Date", id = "ReceivingDate_" })
                        @if (file.ReceivingDateValue != null)
                        {
                            <script>
                                var t = document.getElementById("ReceivingDate_");
                                  t.value = '@file.ReceivingDateValue.Value.ToString("yyyy-MM-dd")';
                            </script>
                        }
                        @Html.ValidationMessageFor(model => file.ReceivingDateValue, "", new { @class = "text-danger" })
                    </div>
                </td>
            </tr>
        }
    }
</tbody>

@Html.TextBoxFor(m =&gt; file.ReceivingDateValue, new { @class = "form-control ReceivingDate ", type = "Date", id = "ReceivingDate_" }) 中的问题是我的问题,因为 ReceivingDateValue 的值绑定正确,当我在 chrome 中检查它时,我找到了写入值,但它的文本框显示错误值 我想在文本框中查看日期以使其可编辑

【问题讨论】:

  • 尝试将值作为属性之一添加到帮助标记:@Html.TextBoxFor(x =&gt; file.FileIDValue, new { @class = "form-control hidden EMPF", value = File.FileIDValue }
  • @Html.TextBoxFor(m =&gt; file.ReceivingDateValue, new { @class = "form-control ReceivingDate ", type = "Date", id = "ReceivingDate_" }) 中的问题值绑定正确
  • 然后试试@Html.TextBoxFor(m => file.ReceivingDateValue, new { @class= "form-control ReceivingDate", type = "Date", id = "ReceivingDate_", value = File.接收日期})

标签: javascript c# razor model-view-controller razor-pages


【解决方案1】:

lambda 表达式x=&gt; file.FileIDValue 将值从客户端绑定到控制器。将值作为属性添加应该从服务器绑定到客户端并提供您正在寻找的结果

@Html.TextBoxFor(x => file.FileIDValue, new { @class = "form-control hidden EMPF", value = File.FileIDValue }

【讨论】:

  • 我在@Html.TextBoxFor(m =&gt; file.ReceivingDateValue, new { @class = "form-control ReceivingDate ", type = "Date", id = "ReceivingDate_" }) 中的问题,因为 ReceivingDateValue 的值绑定正确,当我在 chrome 中检测它时,我找到了写入值,但它的文本框显示错误的值我想在文本框中查看日期以使它可编辑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-03
  • 1970-01-01
  • 2019-10-24
  • 2013-04-03
  • 2023-03-06
  • 2015-04-05
相关资源
最近更新 更多