0

如果在我的控制器中:

public ActionResult Index()
{
     //no code implied
     return View;
}

然后在返回的视图中:

<%if(ViewData["SomeString"].ToString() != "True") {%> show this <%}%>

由于对象引用没有对象,我会在运行时出错。

但是在我做的页面内部:

<%if(Request.QueryString["Something"].ToString() != "True") {%> show this <%}%>

更新:我确实得到了错误。

编辑:看起来他们的行为毕竟是一样的。

4

1 回答 1

3

两者都ViewDataQueryString返回null不存在的密钥。当您尝试在对象引用上调用方法(在您的情况下为ToString)时,您会得到一个.nullNullReferenceException

我不确定在这种情况下有什么不清楚的地方。

于 2010-08-10T14:19:22.587 回答