简体   繁体   English

ASP.NET MVC4中视图中的DatePicker

[英]DatePicker in View in ASP.NET MVC4

I am using ASPX.NET MVC4, with aspx as view engine. 我正在使用ASPX.NET MVC4,将aspx作为视图引擎。 I have a function at my controller, which takes as input a start date and an enddate. 我在控制器上有一个函数,该函数将开始日期和结束日期作为输入。 I want these dates to be given by the user using a DatePicker, or something similar, and after that to be passed at the controller. 我希望这些日期由用户使用DatePicker或类似的名称给出,然后在控制器处传递。

However, I found that asp does not have a DatePicker. 但是,我发现asp没有DatePicker。 How do I use a datepicker for my application? 如何在应用程序中使用日期选择器?

I also looked here and here but I did not find them really helpful. 我也在这里这里看过,但没有发现它们真正有用。 Do you know how I am able to do that? 你知道我能做到吗?

If you're using a standard ASP.NET MVC template then you're very likely already loading/using jQuery. 如果您使用的是标准ASP.NET MVC模板,则很可能已经在加载/使用jQuery。 It's also pretty likely that you're loading/using jQuery UI . 很有可能正在加载/使用jQuery UI (If not, it's easy enough to include . There's even a handy NuGet package for it.) (如果没有,那么包含就很容易了 。甚至还有一个方便的NuGet包 。)

Given this, converting any input type="text" (or @Html.TextBox() or any number of other server-side helpers which emit an input type="text" ) into a "date picker" is a single line of code: 鉴于此,将任何input type="text" (或@Html.TextBox()或发出input type="text"任意数量的其他服务器端帮助程序)转换为“日期选择器”就是一行代码:

$(targetInputs).datepicker();

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

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