I need to pass a value by method get
.
On the start page I have
I need to pass a value by method get
.
On the start page I have
I think the problem of the null reference is given in this command: Session["idrestaurant"].ToString()
because as I see in code you have not yet defined this session variable.
In any case, try to capture the GET parameters in this way:
string miVariableGet = "";
if (Request.QueryString["id"] == null){
//La variable 'id' es nula
}else{
//Se logro capturar el parametro y lo puedes utilizar. Por ejemplo
miVariableGet = Request.QueryString["id"];
}
You should always expect it to be null, since they might not send you anything in the query string or there may be nothing in the session (lost session).
<%
int idrestaurant = 0;
var rawValue = "";
if (Request.QueryString?.Keys.Count == 0)
{//AQUI EL ERROR
rawValue = Session["idrestaurant"];
}
else
{
rawValue = Request.QueryString["id"];
}
if(rawValue !=null){
int.TryParse(rawValue.ToString(), out idrestaurant);
}
Session["idrestaurant"] = idrestaurant;
%>