我正在使用与实体框架的模型绑定,并具有一个Html.TextBoxFor(model => model.date)输入.我知道如何告诉jQuery如何实现一个datepicker而不是在这个上下文中.当用户输入此字段时,需要添加哪些日历弹出窗口?
解决方法
您将需要使用HtmlHelper重载,允许您指定Html属性.然后用jquery选择器来定位它们.
// in view <%= Html.TextBoxFor(x => x.Date,new { @class="datepicker" })%> // in js $(document).ready({ $('.datepicker').datepicker(); });
虽然我建议使用EditorFor而不是.
<%= Html.EditorFor(x => x.Date)%>
您可以创建一个EditorTemplate来处理作为DateTime的任何字段,并输出正确的字段.
创建/Views/Shared/EditorTemplates/DateTime.ascx并将其放在…中
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %> <%= Html.TextBox("",Model.ToShortDateString(),new { @class="datepicker" } )%>
或者如果您需要允许DateTime为null:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %> <%= Html.TextBox("",(Model.HasValue? Model.Value.ToShortDateString():""),new { @class="datepicker"} )%>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。