[英]How to get all active parameters in ASP.NET MVC (2)
I was wondering whether there is a way to create an ActionLink
or similar, that changes only a few parameters of the actual query, and keeps all the other parameters intact. 我想知道是否有一种方法可以创建一个
ActionLink
或类似的方法,该方法仅更改实际查询的几个参数,并使所有其他参数保持不变。 For example if I'm on an URL like http://example.com/Posts/Index?Page=5&OrderBy=Name&OrderDesc=True
I want to change only the Page
, or OrderBy
parameter and keep all other parameters the same, even those I don't yet know of (like when I want to add a Search
parameter or something similar too). 例如,如果我使用的网址为
http://example.com/Posts/Index?Page=5&OrderBy=Name&OrderDesc=True
我只想更改Page
或OrderBy
参数,并保持所有其他参数不变,即使那些我还不知道(例如,当我想添加Search
参数或类似的东西时)。
The header of my current action looks like this: 我当前操作的标题如下:
public ActionResult Index(int? Page, string OrderBy, bool? Desc)
and I'm only interested in the values that this controller "eats". 我只对这个控制器“吃掉”的值感兴趣。 I want however that when I extend this action (for example with a
string Search
parameter) the links should work the same way as before. 但是,我希望当我扩展此操作(例如,使用
string Search
参数)时,链接的工作方式应与以前相同。
Here is what I did already: 这是我已经做过的:
RouteValueDictionary
and fill it with everything from RouteData.Values
RouteValueDictionary
并用RouteData.Values
所有内容填充它
Page
) to the controller are lost Page
)都丢失了 HttpContext.Request.QueryString
to the previous dictionary HttpContext.Request.QueryString
所有内容添加到上一词典
HttpContext.Request.Params
HttpContext.Request.Params
RouteValueDictionary
that is passed to an ActionLink
ActionLink
的RouteValueDictionary
中 So the questions: 所以问题是:
RVD
that has all the data that was passed to the Controller and was used by it? RVD
,具有所有传递到控制器并由其使用的数据? Params
object? Params
对象中过滤掉“垃圾”数据? EDIT: Checked the RouteData.DataTokens
variable, but it's usually empty, and doesn't contain everything I need. 编辑:检查
RouteData.DataTokens
变量,但是它通常为空,并且不包含我需要的所有内容。 It seems to only contain parameters that are needed for the routing somewhere, but not all of the parameters. 它似乎只包含某处路由所需的参数,而不是所有参数。
Have a look in RouteData.DataTokens
. 看看
RouteData.DataTokens
。
RouteData.DataTokens @ MSDN documentation : RouteData.DataTokens @ MSDN文档 :
Gets a collection of custom values that are passed to the route handler but are not used when ASP.NET routing determines whether the route matches a request.
获取传递给路由处理程序但在ASP.NET路由确定路由是否与请求匹配时不使用的自定义值的集合。
HTHs, HTH,
Charles 查尔斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.