在MVC中处理长查询字符串的最佳方法是什么?

ran*_*jez 3 c# asp.net-mvc c#-4.0 asp.net-mvc-3

我正在开发一个可能有很长查询字符串来维护状态的应用程序.

我不确定在动作方法中处理这些长查询字符串的最佳方法是什么,因为我最终会得到一个很长的参数列表.

最好直接从请求对象访问查询字符串参数,还是应该继续创建一个带有很长参数列表的操作方法?

即,需要传递一些配置参数来定制页面.所以我们可能会有一个查询字符串:?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
        }
Run Code Online (Sandbox Code Playgroud)

要么

public ActionResult AvailableTimes()
        {
          var query = Request.Query;
          // Do stuff
        }
Run Code Online (Sandbox Code Playgroud)

提前致谢.

小智 5

创建一个包含查询字符串的所有参数的类.然后在您的操作结果中,使用对象而不是所有参数.

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; }
} 
Run Code Online (Sandbox Code Playgroud)