ASP.NET MVC 参数为NULL异常

allenzhang0007 2011-04-14 08:57:41
直接上代码:
CONTROLER:
public ActionResult ProductHome()
{
//ViewData["Content"] = cs.GetAll();
ViewData["Content"] = Get();
return View();
}

private ArrayList Get()
{
IList<HelperContent> ls = new List<HelperContent>();
ls = cs.GetAll();
//IList < string> lls = new List<string>();
ArrayList myarr = new ArrayList();
if (ls != null)
{
foreach (HelperContent hcon in ls)
{
string rs = hcon.Parentfolder;
string result = rs.Substring(rs.IndexOf("Content") + 7, rs.Length - rs.IndexOf("Content") - 7);
//int i = result.IndexOf("/", 2);
myarr.Add(result);
//lls.Add(hcon.Parentfolder);
}
}
return myarr;
}
这段代码不需要仔细看,就是把截取的string 全部装到arraylist 里去。。。

VIEW:
<% IList<string> Arrylist = (ViewData["Content"] as IEnumerable<string>).ToList<string>(); %>
到这就报错了
argumentnull exception was unhandled by user code
...全文
130 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-04-14
  • 打赏
  • 举报
回复
根据自己后台返回的类型而定的。。

ArrayList myarr = new ArrayList();

<% ArrayList arrylist = (ArrayList)ViewData["Content"]; %>
这样看看

或者后台返回一个List<string> 也可以。
zhenze0 2011-04-14
  • 打赏
  • 举报
回复
Action中不是ArrayList吗?怎么View里面又转成IList了?

这样试试:
<% ArrayList arrylist = (ArrayList)ViewData["Content"]; %>
allenzhang0007 2011-04-14
  • 打赏
  • 举报
回复
默认的路由啊
ycproc 2011-04-14
  • 打赏
  • 举报
回复
路由里面写 参数了么
chen_ya_ping 2011-04-14
  • 打赏
  • 举报
回复
你的那个使用变量前,先判断是不是为null
xiaoqiu1234 2011-04-14
  • 打赏
  • 举报
回复

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧