我正在尝试为这个项目使用jQuery UI日期时间选择器。有一个共享的局部视图,看起来像这样,但它不工作。我的共享文件夹中有一个局部视图,名为DateTime
@model System.DateTime?
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue,
new
{
data_datepicker = true
});它应该会产生这样的效果:
@Html.EditorFor(model => model.Until ,new{@class="date"})我也尝试过脚本,但没有结果。
发布于 2014-01-28 20:09:09
确保使用UIHint标记模型变量。
[DisplayName("Number of Hours")]
[UIHint("HoursOfTheDay")]
public Decimal NumberOfHours { get; set; } 查看这篇文章:http://www.devcurry.com/2013/04/custom-templates-in-aspnet-mvc.html
发布于 2014-01-28 21:00:37
问题是您的模型被标记为DateTime,而不是可以为空的类型DateTime?。
将您的模型属性更改为此属性,它应该会提取该属性:
public DateTime? Until { get; set; } 发布于 2014-01-28 21:11:57
将您的模型属性更改为此
public DateTime Until { get; set; } 和view
@Html.EditorFor(model => model.Until, new { @class = "date" })不需要为DateTimePicker使用Javascript。请参阅此示例http://www.asp.net/mvc/tutorials/javascript/using-the-html5-and-jquery-ui-datepicker-popup-calendar-with-aspnet-mvc/using-the-html5-and-jquery-ui-datepicker-popup-calendar-with-aspnet-mvc-part-1
https://stackoverflow.com/questions/21405218
复制相似问题