2012-05-24 43 views
3

我正在研究一个应用程序,它可能会有非常长的查询字符串来维护状态。在MVC中处理长查询字符串的最佳方式是什么?

我不知道什么是在动作方法中处理这些长查询字符串的最佳方式,因为我最终会得到一长串参数。

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

即需要传递配置参数以定制页面的编号。所以我们可能有一个查询字符串作为这样的:摆脱= 123 &投标= 456 & CID = 789 &做= 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 
     } 

在此先感谢。

+0

最好的选择可能是将查询字符串数据移动到其他位置,如Session或Profile。 – jrummell

+2

给我们一个你可能遇到的例子... – 2012-05-24 17:04:47

+0

@ edmastermind29已经更新后的例子 – ranjez

回答

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; } 
} 
+0

这是否回答你的问题? – Steve

+0

是的,比你@Steve – ranjez

+0

,除非你使用FormMethod.Post,这仍然会导致一个很长的查询字符串。事实上,它会更长,因为变量将是TimeItem.rid,TimeItem.bid,TimeItem.cid等。 – JoeBrockhaus

相关问题