【发布时间】:2011-06-30 02:23:38
【问题描述】:
我正在查看此链接:
它描述了为 MVC 创建一个 jquery datepicker 以在编辑中选择日期。
本教程工作正常,但仅适用于编辑而不是创建。
它有一个模型:
public class Foo
{
public string Name { get; set; }
[DataType(DataType.Date)]
public DateTime Date { get; set; }
}
我修改了它的编辑以创建一个类似的创建:
@model DatePickerTemp.Models.FooEditModel @{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>
Create</h2>
@Model.Message
@using (Html.BeginForm())
{
@Html.EditorFor(m => m.Foo)
<input id="submit" name="submit" type="submit" value="Save" />
}
}
其他代码使用一些jquery:
$(document).ready(function () {
$('.date').datepicker({dateFormat: "dd/mm/yy"});
});
对于任何带有 .date 类的东西:
还有一段代码:
@model DateTime
@Html.TextBox("", Model.ToString("dd/MM/yyyy"), new { @class = "date" })
在类型对象上设置类:
[DataType(DataType.Date)]
创建一个 jquery 日期选择器。
问题是这种类型是不可为空的类型,所以当你运行创建时你会得到:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
有谁知道如何修改代码以使创建工作?
【问题讨论】:
标签: c# jquery asp.net-mvc asp.net-mvc-3 jquery-ui-datepicker