我是ASP.net MVC的新手,目前我正在构建一个小型应用程序,它在数据库中显示数据,如表(列表)。我使用查询字符串将其实现为搜索文本框到控制器。 问题是我想使用表中的标题从搜索结果中对网格数据进行排序,然后查询字符串应该在url中附加当前的queryString。例如,如果我搜索title =“alkf”
http://localhost/search?Title=alkf。 当我想使用价格对网格进行排序时,我希望网址为
http://localhost/search?Title=alkf&sort=price 像那样 我尝试使用这个snipp,但它没有成功。
<table>
<tr>
<th> <%:Html.ActionLink("Title","Search",new {Title=ClienQueryString[0],sort="Title"}
)%>
</th>
<th><%: Html.ActionLink("Price","Search",new {Title=ClienQueryString[0],sort="Price"})%>
</th>
</tr>
<tr>
...
</table>
所以任何人都可以建议我更好地处理这个问题。
答案 0 :(得分:1)
您可以使用Request对象从查询字符串中获取值。尝试这样的事情:
<%: Html.ActionLink("Price", "Search", new { Title=Request["Title"], sort="Price" })%>
答案 1 :(得分:0)
问题可能是ClienQueryString[0]
最好的方法是将搜索字词放入Model
您可能需要为包含字符串(搜索字词)和结果列表的Viewmodel
创建自己的<%: Html.ActionLink("Price","Search",new {Title=Model.SearchString,sort="Price"})%>
。
这是干净利落的方式。
{{1}}