开发者

Using ID generated by Html.EditorFor in a jquery UI extension

So here's a DateTime editor a la NerdDinner's /Views/Shared/EditorTemplates/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>

Since this is a template that's going to be used possibly multiple times on a page, if I'm going to attach the datepicker to each TextBox, they each need a unique ID, and I need to be able to use them in the <script>.

What's the best way to go about doing this?


I'm not much of an MVC programmer, but surely you can just use a class instead of an ID somehow?

<%@ 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜