View层代码 :
<div id="menu" class="menu">
<ul class="tabpage2">
<li id="left_tab1" title="操作菜单" onClick="javascript:border_left('left_tab1','left_menu_cnt1');"><span>博文</span></li>
</ul>
<div id="left_menu_cnt1" class="left_menu_cnt">
<ul id="dleft_tab1">
<li id="now11"><a title="系统设置" href="#" target="content3"><span>系统设置1</span></a></li>
<%
Model.ArticleClass al = ViewData["ArticleClass"] as Model.ArticleClass;
%>
<li id="now12"><%=Html.ActionLink("文章分类管理", "../ArticleClassInfo/Index", new { id = al.userID })%></li>
<li id="now13"><a title="下单记录" href="../ArticleInfo/Index" target="content3"><span>文章管理</span></a></li>
<li id="now17"><a title="上传文件" href="../ArticleInfo/Create" target="content3"><span>发表博文</span></a></li>
<li id="now18"><a title="自定义文件" href="../ArticleClassInfo/Create" target="content3"><span>添加分类</span></a></li>
<li id="now1b"><a title="模板管理" onclick="show_title('生成文件管理')" href="#" target="content3">
<span>模板管理</span></a></li>
</ul>
</div>
Controller层代码:
public class ArticleClassInfoController : Controller
{
ArticleClassInfoDAL acd = new ArticleClassInfoDAL();
UsersInfoDAL ul = new UsersInfoDAL();
public ActionResult Index(int id)
{
Users ut = ul.GetUsersInfo(id);
ArticleClass all = acd.GetArticleClassInfo(ut.userID);
ViewData["ArticleClass"] = all;
return View();
}
Model层代码:
/// <summary>
/// 绑定文章分类列表
/// </summary>
/// <returns></returns>
public List<ArticleClass> BindArticleClassInfo(int id)
{
var linq = (from c in acl.ArticleClass
where c.userID==id
select new
{
articleClassID=c.articleClassID,
articleClassName=c.articleClassName,
userID=c.userID
}).ToList();
List<ArticleClass> all = new List<ArticleClass>();
for (int i = 0; i < linq.Count; i++)
{
all.Add(new ArticleClass { articleClassID=linq[i].articleClassID, articleClassName=linq[i].articleClassName,userID=linq[i].userID});
}
return all;
}
/// <summary>
/// 得到文章类别信息
/// </summary>
/// <returns></returns>
public ArticleClass GetArticleClassInfo(int id)
{
var linq = acl.ArticleClass.Where(p=>p.articleClassID==id).Single();
ArticleClass ut = new ArticleClass();
ut.articleClassID= linq.articleClassID;
ut.articleClassName = linq.articleClassName;
return ut;
}
al.userID
最可能是这儿的问题,你断点看看al是否为null