私はEntityFramework CodeFirst MVC3を使用します。私のモデルのnull可能なプロパティが私の作成ビューに表示されました
@model PostCreateViewModel
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.PostToCreate.PublishDate)
@Html.EditorFor(model => model.PostToCreate.PublishDate)
...
}
私は上のエラーを得た:私のビューを作成するには
public ActionResult Create()
{
PostCreateViewModel viewModel = new PostCreateViewModel
{
PostToCreate = new PostFullViewModel(),
Authors = m_AccountBusiness.GetAllUsers().Select(x => new SelectListItem { Text = x.UserName, Value = x.UserID.ToString() })
};
return View(viewModel);
}
:ここ
public class PostFullViewModel
{
public int PostID { get; set; }
...
public DateTime? PublishDate { get; set; }
...
}
は私のアクションコントローラを作成している:私のモデルでは、私はこのようなnull入力可能プロパティを定義しエディター用:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
どのようにして、作成ビューでPublishDateが空であることを示すことができますか?
ありがとうございました。だから、あなたは可能性
@model DateTime
...
:
を作成中に何らかの問題を持っていなかった、ダーリンと思いますか?あなたはもっと詳しく説明できますか? – Ray
質問を更新して、作成アクションコントローラを表示しました。 – Bronzato