EditorTemplate中的TextboxFor不会保存值

问题描述 投票:0回答:1

我在MVC中使用EditorTemplate时遇到了麻烦。

我的EditorTemplate看起来像这样:

    <script type="text/javascript">
    $(function () {
        $('.datepicker').datepicker({
            dateFormat: 'dd-mm-yy'
        });
    });
</script>

<tr>
    <td>@Html.DisplayFor(model => model.Title)</td>
    <td>@Html.DisplayFor(model => model.Authors)</td>
    <td><a href="/administration/products/bookz/[email protected]" target="_blank">@Html.DisplayFor(model => model.ISBN13)</a></td>
    <td>@extPrice.ToString("N2") </td >
    <td>@Html.TextBoxFor(model => model.Price, new { data_val_number = "The field Price must be a number." })</td>
    <td>@Html.TextBoxFor(model => model.MemberPriceStartDate, "{0:dd-MM-yyyy}", new { @class = "form-control datepicker" })</td>
    <td>@Html.TextBoxFor(model => model.MemberPriceEndDate, "{0:dd-MM-yyyy}", new { @class = "form-control datepicker" })</td>
    @Html.HiddenFor(model => model.BookId)
</tr>

@model的类型为Books(由于数据库混乱,书籍是单数的-_-)。

从视图中调用EditorTemplate,如下所示:

@Html.EditorFor(model => model)

@model的类型为IEnumerable<Books>

发布到我的控制器时,Books.Price正确传递,但Books.MemberPriceStartDateBooks.MemberPriceEndDate始终为空。隐藏的字段Books.BookId也正确传递。

关于为什么会发生这种情况的任何想法?

编辑:

以下是Books对象的相关属性:

public Nullable<System.DateTime> MemberPriceStartDate { get; set; }
public Nullable<System.DateTime> MemberPriceEndDate { get; set; }
public Nullable<decimal> Price { get; set; }
public int BookId { get; set; }
c# asp.net-mvc mvc-editor-templates asp.net-mvc-5.2
1个回答
0
投票

在您的特定字段的模型日期格式和输入日期格式 - “dateFormat:'dd-mm-yy'”可能不匹配。

© www.soinside.com 2019 - 2024. All rights reserved.