我在asp.net核心中使用了BeginCollectionItem。在这个集合中,我使用了kendo组合框和datepicker,这两个数据在发布数据时都不与模型列表绑定。任何人都知道。
以下是cshtml文件的代码示例
@using HtmlHelpers.BeginCollectionItemCore
@using DemoProject.Model
@model BatchDetail
<tr data-rownum="@Model.Seq">
@using (Html.BeginCollectionItem("oBatchDetails"))
{
<td>
@Html.EditorFor(model => model.CheckCardNo, new { htmlAttributes = new { @class = "form-control input-sm patientCheckCard clsAlphaNumericText", maxlength = "50", autocomplete = "off" } })
</td>
<td>
@(Html.Kendo().DatePickerFor(model => model.CheckDate).Format("MM/dd/yyyy").HtmlAttributes(new { style = "width:115px", @class = "smalldtpicker paidDate", autocomplete = "off", @type = "" }))
</td>
}
</tr>
当我在控制台中看到$("#formid").serialize()
时。我发现了以下结果。
oBatchDetails%5B25e11650-70cd-4d04-9fe0-4ce0e621cbfd%5D.CheckCardNo=123456789&
CheckDate=12%2F27%2F2021&
其中检查日期应为oBatchDetails%5B25e11650-70cd-4d04-9fe0-4ce0e621cbfd%5D.CheckDate=12%2F27%2F2021&
但Begin集合项无法处理此剑道日期选择器。
我找到了剑道控制的解决方案。为了解决这个问题,需要调用render函数来处理kendo控件。从获得参考https://www.telerik.com/forums/datepicker-error-with-core-5-0
以下是更正后的代码,它与begin集合项核心一起工作得很好。
@using HtmlHelpers.BeginCollectionItemCore
@using DemoProject.Model
@model BatchDetail
<tr data-rownum="@Model.Seq">
@using (Html.BeginCollectionItem("oBatchDetails"))
{
<td>
@Html.EditorFor(model => model.CheckCardNo, new { htmlAttributes = new { @class = "form-control input-sm patientCheckCard clsAlphaNumericText", maxlength = "50", autocomplete = "off" } })
</td>
<td>
@{
Html.Kendo().DatePickerFor(model => model.CheckDate).Format("MM/dd/yyyy").HtmlAttributes(new { style = "width:115px", @class = "smalldtpicker paidDate", autocomplete = "off", @type = "" }).Render();
}
</td>
}
</tr>
您可以尝试在$(function(){})
:中将CheckDate
的名称更改为正确的格式
$(function () {
$("input[name='CheckDate']").attr("name", $("input[id$='CheckCardNo']").attr("name").replace("CheckCardNo", "CheckDate"));
});