简体   繁体   English

在aspnet核心中编辑查询字符串

[英]Editing querystring in aspnet core

My simple usecase is changing page number. 我的简单用例是更改页码。 Like: http://localhost?page=1 to: http://localhost?page=2 喜欢: http:// localhost?page = 1 to: http:// localhost?page = 2

I would like to be able to add/update/remove segments from querystring. 我希望能够从查询字符串中添加/更新/删除段。

There are QueryString and QueryBuilder classes, however they support only adding segments, not changing them. 有QueryString和QueryBuilder类,但它们只支持添加段,而不是更改它们。 WebUtilities.QueryHelpers parses querystring to dictionary, but that is hard to edit, because you need to create variable, and also you need to check if key exists. WebUtilities.QueryHelpers将查询字符串解析为字典,但这很难编辑,因为您需要创建变量,还需要检查密钥是否存在。

My frontend engineers need simple and foolproof way of manipulating it, to use with server generated url or IUrlHelper . 我的前端工程师需要简单而万无一失的操作方法,与服务器生成的url或IUrlHelper Is there builtin way of doing it? 有内置的方式吗?

My ideal api: 我的理想api:

Query(Model.Uri).Update('page', '2').Add('sort', 'asc').Remove('filter').ToString();

尝试Flurl ,它是满足您需求的完美工具;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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