2012-04-17 114 views
0

我有2个索引操作POST和GET当我提交的表单POST操作返回:获取URL ASP.NET MVC 3

return RedirectToAction("Index"); 

编辑:

我得到索引操作可以获取一些参数来支持搜索和过滤返回的List。像这样:

public ActionResult Index(string search = "", long searchItem = 0, long RC = 0, long Page = 1) 

我用分页目录,有一个DropDownList,显示行数在每页,我写form.submited一个jQuery脚本改变这个下拉菜单中,当形式RedirectTAction提交 我输了我的参数如下代码:

[HttpPost] 
public ActionResult Index(FormCollection collection, string search = "") { 

    long RowCount = 0; 
    long.TryParse(string.Format("{0}", collection["RowCount"]), out RowCount); 

//More implement 

return RedirectToAction("Index", new { RC = RowCount, search = search, searchItem = Id }); 

那么有没有什么办法可以在Post Action中获取Url或url参数?你在这种情况下的建议是什么?

+0

什么是url参数?通常当你POST时,没有查询字符串参数。或者有你的情况吗?你在说什么查询字符串参数或路由值或POST值? – 2012-04-17 09:47:57

+0

@DarinDimitrov我更新问题 – Saeid 2012-04-17 09:58:12

回答

1

你可以捕捉一个RouteValueDictionary所有查询字符串参数重定向之前:

var query = new RouteValueDictionary(
    Request 
     .QueryString 
     .Keys 
     .OfType<string>() 
     .ToDictionary(key => key, key => (object)Request.QueryString[key]) 
); 
return RedirectToAction("Index", query); 

这将只保留查询字符串参数。如果要添加路由值和POST值,可以将它们连接到结果。

+0

谢谢,这真的很有帮助,实际上我不想传递所有的路由值作为发布,所以我使用'if(Request.QueryString.AllKeys.Contains(“searchItem”))long.TryParse (Request.QueryString.GetValues(“searchItem”)。FirstOrDefault(),out Id);' – Saeid 2012-04-17 10:34:38