Controller Action方法:
public ActionResult Index(int postID)
{
ClassBlogDBDataContext cb = new ClassBlogDBDataContext();
ViewData["post"] =(IQueryable<T_Post>) cb.T_Post.SingleOrDefault(p => p.PostID == postID);
return View("Index");
}传递一个ViewData["post"]
在index 中
<% foreach (var post in ViewData["post"] as List<T_Post>)
{ %>出现错误
未将对象引用设置到对象的实例。ViewData["post"] as List<T_Post> 转换失败!!! 为null试了许多页用VIEWDATA方法传递值转为强类型的就会失败 ...何解????
public ActionResult Index(int postID)
{
ClassBlogDBDataContext cb = new ClassBlogDBDataContext();
ViewData["post"] =(IQueryable<T_Post>) cb.T_Post.SingleOrDefault(p => p.PostID == postID);
return View("Index");
}传递一个ViewData["post"]
在index 中
<% foreach (var post in ViewData["post"] as List<T_Post>)
{ %>出现错误
未将对象引用设置到对象的实例。ViewData["post"] as List<T_Post> 转换失败!!! 为null试了许多页用VIEWDATA方法传递值转为强类型的就会失败 ...何解????
if(list!=null)
{
foreach (var post in list)
{ %>
这个只是一个声名, .ToList();/ToArray();才是取出数据了
这样理解有问题么.