Response.Redirect passing a value dynamically
net c#.
I have a page A with this code
//ON PAGE A:
string contentId = ContentIdFromUrl;
Response.Redirect("~/x/y/b.aspx?ContentId={0}"content开发者_JAVA技巧Id);
and I need redirect the user to page B passing in the URL a variable in my case ContentId
.
I receive a syntax error with my code.
Could you write a correct version?
Thanks for your time.
string contentId = ContentIdFromUrl;
Response.Redirect("~/x/y/b.aspx?ContentId="+HttpUtility.UrlEncode(contentId));
You'll have to change the last line to:
Response.Redirect(string.Format("~/x/y/b.aspx?ContentId={0}",contentId));
as it won't compile as it is.
Update: Another way to do this is:
Response.Redirect("~/x/y/b.aspx?ContentId=" + contentId);
string contentId = ContentIdFromUrl;
Response.Redirect(string.Format("~/x/y/b.aspx?ContentId={0}",contentId));
Response.Redirect(string.Format("~/x/y/b.aspx?ContentId={0}",contentId));
精彩评论