附加到 ASP.NET MVC 中的当前 URL

发布于 2024-07-29 05:06:27 字数 926 浏览 3 评论 0原文

我知道这可能很容易实现,但我在寻找答案时遇到了一些麻烦。 与 Stackoverflow 允许您使用标签继续深入研究问题类似,我正在尝试实现相同的功能。 因此,我在 MVC 页面上创建了一个“标签”列表,如下所示:

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

这会生成类似 http://mysite.com/controller/index?tags=MyTageName

我有一个控制器方法,它采用 tagName 参数值,我们很好......在第一级。 我希望能够获取此处返回的视图,并针对上述代码中的每个标签,将新标签名称附加到 url 中。 我新生成的 URL 如下所示:

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

希望这是有道理的......有什么想法吗? 编写我自己的 HTMLHelper? 我缺少 URL.namespace 中的神奇函数吗? :)

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? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会发光的星星闪亮亮i 2024-08-05 05:06:27

我想这就是你想做的:

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

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%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文