モデルアイテムを持っています
public class EntryInputModel
{
...
[Required(ErrorMessage = "Description is required.", AllowEmptyStrings = false)]
public virtual string Description { get; set; }
}
とコントローラーアクション
public ActionResult Add([Bind(Exclude = "Id")] EntryInputModel newEntry)
{
if (ModelState.IsValid)
{
var entry = Mapper.Map<EntryInputModel, Entry>(newEntry);
repository.Add(entry);
unitOfWork.SaveChanges();
return RedirectToAction("Details", new { id = entry.Id });
}
return RedirectToAction("Create");
}
EntryInputModel
単体テストでを作成し、Description
プロパティをに設定null
してアクションメソッドに渡すと、ModelState.IsValid == true
デバッグして検証したにもかかわらず、が取得されnewEntry.Description == null
ます。
なぜこれが機能しないのですか?