下面是日期时间编辑器a la nerddinner's/views/shared/editoremplates/datetime.ascx:
%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %> <%: Html.TextBox("", String.Format("{0:yyyy-MM-dd HH:mm}", Model))%> <script type="text/javascript"> $(function () { $("#date").datepicker({ showOn: 'focus' }); }); </script>
因为这是一个可能会在一个页面上多次使用的模板,如果我要将日期选择器附加到每个文本框,它们都需要唯一的ID,并且我需要能够在<script>中使用它们。
做这个最好的方法是什么?
我不是一个MVC程序员,但你肯定可以用一个类代替一个ID吗?
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %> <%: Html.TextBox("", String.Format("{0:yyyy-MM-dd HH:mm}", Model, new { @class = "datepicker" }))%> <script type="text/javascript"> $(function () { $(".datepicker").datepicker({ showOn: 'focus' }); }); </script>