如何将条件查询字符串添加到 MVC 4 中的 URL?

How can I add conditional query string to the URL in MVC 4?

我在向 URL 添加条件查询字符串时遇到了一些问题。

if the url == domain/controller/action then 
    do nothing

if the url == domain/controller/action?referenceNumber=xxxx then
    url = domain/controller/action?referenceNumber=xxxx&newParameter=yyyy

我试过重写 OnActionExecuting 但没有任何运气,而且我对 RouteConfig 不是很了解。

想法?

我试过以下方法

protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
{
   var path = requestContext.HttpContext.Request.RawUrl;

   if(myCondition)
   {
      requestContext.HttpContext.RewritePath(string.Format("{0}&newParameter={1}", path, getNewParameter()); 
   }

   return base.BeginExecute(requestContext, callback, state);
}

这会更新 HttpContext.Request.Url 但不会在浏览器中反映 URL。

如何克服这个挑战?有什么线索吗?

我能够使用以下方法解决问题...

GET 方法

public ActionResult Action(string referenceNumber, string newParameter){...}

POST 方法

public ActionResult Action(Object myObject, string newParameter){...}

结果是浏览器正在显示

domain/controller/action?referenceNumber=xxxx&newParameter=yyyy