user2232273
user2232273

Reputation: 4964

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");

Upvotes: 3

Views: 3473

Answers (1)

Jace Rhea
Jace Rhea

Reputation: 5018

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);

Upvotes: 7

Related Questions