在 MVC 中处理长查询字符串的最佳方法是什么
本文关键字:最佳 方法 是什么 字符串 查询 MVC 处理 | 更新日期: 2023-09-27 18:35:26
我正在开发一个应用程序,该应用程序可能会有很长的查询字符串来维护状态。
我不确定在操作方法中处理这些长查询字符串的最佳方法是什么,因为我最终会得到一个很长的参数列表。
最好直接从请求对象访问查询字符串参数,还是应该继续创建一个具有很长参数列表的操作方法?
即需要传入一个数字 A 配置参数来自定义页面。 所以我们可能有一个这样的查询字符串:?rid=123&bid=456&cid=789&did=aaa&bg=333&f=999&.....
public ActionResult AvailableTimes(int rid, int bid, int cid, string did, string bg, string f......)
{
// Do stuff
}
或
public ActionResult AvailableTimes()
{
var query = Request.Query;
// Do stuff
}
提前谢谢。
创建一个包含查询字符串的所有参数的类。然后在操作结果中,使用对象而不是所有参数。
public ActionResult AvailableTimes(TimeItem time)
{
// Do stuff with time
}
public Class TimeItem
{
int rid { get; set; }
int bid { get; set; }
int cid { get; set; }
string did { get; set; }
string bg { get; set; }
}