简体   繁体   中英

MVC - Delete QueryString

I'm working on a project and I want to do is to clear the querystring in my url bar.

but until now i haven´t much luck..

hope that someone can help me with this..

this is one of my code which i trying to do:

System.Reflection.PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty( "IsReadOnly", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
isreadonly.SetValue(this.Request.QueryString, false, null);
this.Request.QueryString.Remove("abc");

The url of the Request can not be changed. The url of the Request is what the user has requested, it has already happened in the past.

You probably want to redirect the user to the url without the query string. Taken from this question ...

var uri = new Uri("http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
string path = uri.GetLeftPart(UriPartial.Path);
return Redirect(path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM