你调用的对象是空的。在查询字符串中 [英] Object reference not set to an instance of an object. in query string
本文介绍了你调用的对象是空的。在查询字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请一些人说明为什么会发生这个错误对象引用未设置为object.in此代码的实例。在此行中发生错误
string blog_title = Request.QueryString [blog_title ] .ToString();
Pls some one tell that why this error is occurred Object reference not set to an instance of an object.in this code.in this line the error occurred
string blog_title = Request.QueryString[blog_title].ToString();
if (!IsPostBack)
{
//blog_title = Session["blog_title"].ToString();
string blog_title = Request.QueryString["blog_title"].ToString();
if (Request.QueryString["blog_title"] != null)
{
try
{
blog_title = (Request.QueryString["blog_title"]);
}
catch
{
// deal with it
Response.Redirect("blog/Default.aspx");
}
}
list_bind();
frm_bind();
}
推荐答案
简单:没有名称在变量中的QueryStringblog_title
您的意思是写:
Simple: there is no QueryString with the name that is in teh variableblog_title
Did you mean to write:
string blog_title = Request.QueryString["blog_title"].ToString();
而不是
Instead of
string blog_title = Request.QueryString[blog_title].ToString();
在请求查询字符串时,在将值传递给它之前它不会成为对象,并且确认该值存在,此时它变为一个有效的对象。
例如,
When requesting a querystring, it doesn''t become an object until the value is passed to it, and the value is confirmed to exist, at that point it becomes a valid object.
So for example,
httpcontext.current.request.querystring("apple")
在确认苹果存在之前无效
所以你先测试苹果的存在,然后问佛r值为
在vb中,不确定在c#
is not valid until the existence of apple is confirmed
So you test for the existance of apple first, and then ask for the value
in vb its, not sure in c#
if not (httpcontext.current.request.querystring("apple") is nothing) then
''The object surely exist, so get the value now
Dim apples as string = httpcontext.current.request.querystring("apple")
end if
这篇关于你调用的对象是空的。在查询字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文