views:

473

answers:

1

I know that this is probably something easy to implement, but I am having a bit of trouble finding an answer. Similar to how Stackoverflow allows you to continue to drill down into questions using tags, I am trying to implement the same. So, I have created a list of 'tags' on my MVC page that looks like this:

<%For Each item As myItem In ViewData("topTags")%>
    <li><%=Html.ActionLink(Html.Encode(item.tagName), "Index", New With {.tags = item.tagName})%</li>
<%Next%>

This generates nice URLs that look like http://mysite.com/controller/index?tags=MyTageName

I have a controller method that takes the tagName parameter value and we are good to go...on the first level. I want to be able to take the view that is returned here and for each of my tags in the above code, append the new tag name to the url. My new generated URLs would look like:

http://mysite.com/controller/index?tags=TagNameIClickedBefore+TagNameInForEachLoop

Hope this makes sense...any ideas? Write my own HTMLHelper? A magic function within URL.namespace I am missing? :)

+2  A: 

I guess this is what you want to do :

<%For Each item As myItem In ViewData("topTags")%>
   <li><%=Html.ActionLink(Html.Encode(item.tagName), "Index", 
      New With {.tags = Request.QueryString("tags") & "+" & item.tagName})%></li>
<%Next%>
çağdaş
That did it, and definately easy enough. I have a if then checking to see if request.querystring("Tags") is empty in the loop. One more question, how does one get the + sign to show without being htmlEncoded or is that just bad practice?
Tommy
I think it would be better if you just used space there, instead of + sign.
çağdaş