如何将整数参数传递给查询字符串 [英] How to pass integer parameter to query string

查看:87
本文介绍了如何将整数参数传递给查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我重定向到页面时,我需要将int数据传递给Id,但当我把它放在之间时,我将ID读取为字符串并且我厌倦了下面的代码但是当我将varchar值转换为时,我的错误转换失败了数据类型int



当我在asp.net标签中执行它时工作正常







我尝试了什么:



Response.Redirect(View.aspx?Id =+ HttpContext.Current.Request.QueryString [MaId]。ToString());





这也不起作用

Response.Redirect(View.aspx?Id =+ Eval(MaId) ));

I need to pass int data to Id when I redirect to the page but the id is being read as string when I put it between " " and I tired the code below but I got error conversion failed when converting the varchar value to data type int

when I did it in asp.net tag it works fine



What I have tried:

Response.Redirect("View.aspx?Id="+ HttpContext.Current.Request.QueryString["MaId"].ToString());


and this also not working
Response.Redirect("View.aspx?Id="+ Eval("MaId") );

推荐答案

你必须把它作为字符串传递,查询字符串参数总是字符串。你的View.aspx页面需要将其转换回int



You have to pass it as a string, querystring params are always string. Your View.aspx page needs to convert it back to an int

int id = 0;
int.TryParse(Request.QueryString["id"], out id);


这篇关于如何将整数参数传递给查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆