【发布时间】:2018-06-26 13:07:53
【问题描述】:
我有这个“小”问题。 我创建了一个项目 MVC,我需要在其中注册一个具有不同字段的用户。 (我只给你看一部分。) 一个特定的领域,给我一个问题: 在 DateOfBirth 领域,我在 jquery
上实现了一个日期选择器起初我得到了我之前录制的所有旧数据,我的日历落后了,所以我无法选择日期:
有没有办法让缓存消失而只有日历?
@model WebApplication2.Models.Person
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Person</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DateOfBirth, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateOfBirth, new { htmlAttributes = new { @class = "datepicker form-control" } })
@Html.ValidationMessageFor(model => model.DateOfBirth, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "ListPerson")
</div>
<link href="~/Content/themes/base/jquery-ui.min.css" rel="stylesheet" />
@section Scripts {
<script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
@Scripts.Render("~/bundles/jqueryval")
<script>
$(function() {
$(".datepicker").datepicker(
{
dateFormat: "yy/mm/dd",
changeMonth: true,
changeYear : true
});
});
</script>
}
起初我以为它只是浏览器的缓存,我测试了很多(IE11,Mozilla,Chrome),我清理了缓存,但似乎将日期存储在应用程序缓存中。 你知道这可能是什么原因吗?
亲切的问候。
【问题讨论】:
-
尝试添加
autocomplete="off"属性 -
谢谢!!我按照你的指示解决了 :) @Html.EditorFor(model => model.DateOfBirth, new { htmlAttributes = new { @class= "datepicker form-control", autocomplete = "off" } })
标签: asp.net-mvc caching datepicker editorfor