这是我的 Get actionresult :
public ActionResult Add()
{
ViewData["categoryList"]= _categoryRepository.GetAllCategory().
ToSelectList(c => c.Id, c => c.Name);
return View("Add");
}
这是我呈现 categoryList 的剃须刀,我对此没有任何问题!
<div>
@Html.LabelFor(b => b.Category)
@Html.DropDownList("Category", ViewData["categoryList"] as IEnumerable<SelectListItem>)
@Html.ValidationMessageFor(b => b.Category)
</div>
最后在提交页面后,类别选择通过空值发送来发布这个动作
[HttpPost]
public ActionResult Add(BlogPost blogPost)
{
if (ModelState.IsValid)
{
blogPost.PublishDate = DateTime.Now;
_blogPostRepository.AddPost(blogPost);
_blogPostRepository.Save();
return RedirectToAction("Add");
}
return new HttpNotFoundResult("An Error Accoured while requesting your order!");
}
谁能告诉我为什么?