0

I am newbie to ASP.net MVC, currently I am building small application which displays data from database 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.

2 Answers 2

1

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" })%>
Sign up to request clarification or add additional context in comments.

Comments

0

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"})%>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.