asp:Repeater 和 ActionLink

发布于 2024-09-13 06:00:04 字数 95 浏览 0 评论 0原文

我可以一起使用 asp:Repeater 和 Html.ActionLink 来创建动态菜单吗?或者还有其他方法可以使用吗?

注意:我从 SQL 获取菜单列表。

Am I able to use asp:Repeater and Html.ActionLink together for creating a dynamic menu? Or is there any other methods that I can use it?

Note: I'm getting the menu list from SQL.

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

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

发布评论

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

评论(2

秋凉 2024-09-20 06:00:04

如果您使用 HTML.ActionLink,我将假设您使用 ASP MVC 1 或 2。如果是这种情况,您需要做的就是通过 Model 或 ViewModel 将项目列表传递到视图,并在视图中创建一个 for every 循环来显示项目,而不是使用中继器控制。

另一种选择是创建一个局部视图,将菜单项列表传递到其中,并在其中创建 for every 循环,然后在需要显示菜单的位置呈现局部视图。

如果您将菜单放在主页中,它将自动显示在每个位置。

I'm going to assume you are using ASP MVC 1 or 2 if you're using HTML.ActionLink. If that is the case, what you'll want to do is pass your list of items to the view through your Model or ViewModel and in the view, create a for each loop to display the items instead of using a repeater control.

Another option is to create a partial view that you pass your list of menu items to and create the for each loop in there then render the partial where ever you need to show your menu.

if you put the menu in the Master Page it will automatically show up every where.

酒与心事 2024-09-20 06:00:04

我想可以,网上有很多关于如何在MVC代码中使用asp控件的信息。另外,MVC似乎有自己的转发器: http:// davidhayden.com/blog/dave/archive/2009/04/07/ASPNETMVCControlsASPNETMVCFuturesRepeaterControlExample.aspx

I think you can, there are a lot of information on the web about how to use asp controls in MVC code. also, MVC seems to have its own repeater: http://davidhayden.com/blog/dave/archive/2009/04/07/ASPNETMVCControlsASPNETMVCFuturesRepeaterControlExample.aspx

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