添加查询字符串值的路线字典ActionLink的 [英] Add query string as route value dictionary to ActionLink
本文介绍了添加查询字符串值的路线字典ActionLink的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创造一个ActionLink的从网格导出数据。网格是通过从查询字符串值过滤。下面是URL的一个例子:
http://www.mysite.com/GridPage?Column=Name&Direction=Ascending&searchName=text
这里的code到我的ActionLink的添加到页面:
@ Html.ActionLink(导出到Excel,//链接文本
导出,//动作名称
GridPage,//控制器名称
Request.QueryString.ToRouteDic()//路由值
新{@class =出口})// HTML属性
在显示的链接,网址是:
<$p$p><$c$c>http://www.mysite.com/GridPage/Export?Count=3&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D我在做什么错了?
解决方案
试试这个:
我不知道这是最干净的或最正确的方式,但它确实工作
我没有使用你的扩展方法。你必须重返是:
@ {
RouteValueDictionary tRVD =新RouteValueDictionary(ViewContext.RouteData.Values);
的foreach(在Request.QueryString.Keys字符串键)
{
tRVD [关键] =的Request.QueryString [关键]的ToString();
}
}
然后
@ Html.ActionLink(导出到Excel,//链接文本
导出,//动作名称
GridPage,//控制器名称
tRVD,
新字典&LT;字符串对象&gt; {{类,出口}})// HTML属性
结果
带班导出
I'm trying to create an ActionLink to export data from a grid. The grid is filtered by values from the query string. Here's an example of the url:
http://www.mysite.com/GridPage?Column=Name&Direction=Ascending&searchName=text
Here's the code to add my ActionLink to the page:
@Html.ActionLink("Export to Excel", // link text
"Export", // action name
"GridPage", // controller name
Request.QueryString.ToRouteDic(), // route values
new { @class = "export"}) // html attributes
When the link is displayed, the url is this:
http://www.mysite.com/GridPage/Export?Count=3&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D
What am I doing wrong?
解决方案
Try this:
I'm not sure this is the cleanest or most correct way but it does work
I didn't use your extension method. You'll have to reintegrate that:
@{
RouteValueDictionary tRVD = new RouteValueDictionary(ViewContext.RouteData.Values);
foreach (string key in Request.QueryString.Keys )
{
tRVD[key]=Request.QueryString[key].ToString();
}
}
then
@Html.ActionLink("Export to Excel", // link text
"Export", // action name
"GridPage", // controller name
tRVD,
new Dictionary<string, object> { { "class", "export" } }) // html attributes
Results in
with class export
这篇关于添加查询字符串值的路线字典ActionLink的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文