【发布时间】:2019-07-04 16:14:30
【问题描述】:
我无法找到解决方案,因为我认为这是一个错误,或者我没有看到我应该拥有的东西。
我将模型从受控传递到作为强类型数据的视图。但是,只有一个参数有问题,它在回发后清除它的数据。
当我点击搜索..
您可以在这里看到,Closed Time 的日期仍然存在,但 Cut Off 时间的文本已经消失。最后看到的日期是@Model.CutOffTimeFrom - @Model.CutOffTimeTo的值,只是为了看数据是被清除还是删除,其实不是,只是EditorFor上的显示被删除了。
我也试过这个one,使用<input>标签,但它仍然是相同的输出。
下面是我的模型:
[AssertThat("CutOffTimeFrom <= CutOffTimeTo", ErrorMessage = "Date To should be greater than Date From")]
[RequiredIf("CutOffTimeFrom != null", ErrorMessage = "Date From is required")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? CutOffTimeFrom { get; set; }
[RequiredIf("CutOffTimeTo != null", ErrorMessage = "Cut Off Time From is required")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? CutOffTimeTo { get; set; }
这是视图:
<div>
@*<input type="date" name="CutOffTimeFrom" value="@Model.CutOffTimeFrom" class="form-control input-sm" />-<input type="date" name="CutOffTimeTo" value="@Model.CutOffTimeTo" class="form-control input-sm" />*@
@Html.EditorFor(m => m.CutOffTimeFrom, new { htmlAttributes = new { @class = "form-control input-sm" } }) - @Html.EditorFor(m => m.CutOffTimeTo, new { htmlAttributes = new { @class = "form-control input-sm" } })
@Html.ValidationMessageFor(model => model.CutOffTimeFrom, "", new { @class = "text-danger" })
@Html.ValidationMessageFor(model => model.CutOffTimeTo, "", new { @class = "text-danger" })
</div>
所有其他字段都可以正常工作。只有Cut Off时间被清除,虽然它满足搜索条件,但仍然在模型上传递值,但它只是不显示在视图上。
有人遇到过这个问题吗?
【问题讨论】:
标签: html razor model-view-controller model postback