简体   繁体   English

如何在MVC3 aspx视图引擎中使用jquery创建Calendar控件

[英]How to create Calendar control using jquery in MVC3 aspx view engine

I am working on an ASP.Net MVC3 project. 我正在研究ASP.Net MVC3项目。 I am currently developing a page that has one date field and I want to use the date time jQuery picker control. 我目前正在开发一个具有一个日期字段的页面,并且我想使用日期时间jQuery选择器控件。

只用datepicker编写jQuery UI下载如何?

If you want to make a lasting solution, then there are a number of ways you can go about doing this. 如果您想提供持久的解决方案,则可以采用多种方法。 The one I prefer (and is shown on Pluralsight): 我更喜欢的一个(在Pluralsight上显示):

Create an Editor Template for the date time data type (~/View/Shared/Editor Templates): 为日期时间数据类型创建一个编辑器模板(〜/ View / Shared / Editor Templates):

@model System.DateTime

@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { data_datepicker = true })

Then in the View/Layout have the jQuery and jQuery UI called before running the following wire up: 然后在“视图/布局”中调用jQuery和jQuery UI,然后运行以下连线:

$(document).ready(function () {
    $(":input[data-datepicker]").datepicker();
})

The benefit of this approach, means that every time you have a Date Time field on the page, it will 'just work' as the wire up jQuery finds all the input elments on the page that have the "data-datepicker" attribute added to them (you can make the data- attribute whatever you like so long as they match in the editor and the wire up jQuery). 这种方法的好处是,每当您在页面上有一个“日期时间”字段时,它都会“正常工作”,因为jQuery会在页面上找到添加了“ data-datepicker”属性的所有输入元素。它们(只要它们在编辑器和jQuery中匹配,就可以使data-attribute随心所欲)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM