开发者

How do I append query string in an ASP MVC project?

I am newbie to ASP.net MVC, currently I am building small application which displays data from dat开发者_如何学Cabase in grid like table (list). I had implement it search textbox using query string to the controller. The problem is I want to sort the grid data from the search result using its header in the table then the querystring should be appended with the currently queryString in the url. E.g if I search for title="alkf"

http://localhost/search?Title=alkf. When I want to sort the grid using the price, I want the url to be

http://localhost/search?Title=alkf&sort=price like that I try to do using this snipp but It did't work out.

<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>

so can anyone suggest me a better way to handle this.


You can use the Request object to get values from the query string. Try something like this:

<%: Html.ActionLink("Price", "Search", new { Title=Request["Title"], sort="Price" })%>


the problem is probably the ClienQueryString[0] The best way is to put the search term into your Model

You probably need to make your own Viewmodel for that containing a string (the search term) and a List of results.

That's the clean way to go.

<%: Html.ActionLink("Price","Search",new {Title=Model.SearchString,sort="Price"})%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜